当前位置: 首页 > news >正文

柳州住房和城乡建设厅网站网站设计就业怎么样

柳州住房和城乡建设厅网站,网站设计就业怎么样,禾天姿网站建设,深圳易捷网站建设UE5视频看了不少,但基本都是蓝图如何搞,或者改一下属性,理解UE系统现有组件使用的。一直对C脚本和蓝图之间的关系不是很理解,看到一个视频讲的很好,我也做笔记记录一下。 我的环境是UE5.3.2. 创建UE空项目 我们创建…

UE5视频看了不少,但基本都是蓝图如何搞,或者改一下属性,理解UE系统现有组件使用的。一直对C++脚本和蓝图之间的关系不是很理解,看到一个视频讲的很好,我也做笔记记录一下。

我的环境是UE5.3.2.

创建UE空项目

我们创建一个空项目
在这里插入图片描述

创建类MyPlayer

进入项目后,我们直接创建一个C++类。
在这里插入图片描述
因为是从基础理解,所以就选择更基础的Pawn类,不使用Character类。
在这里插入图片描述
我起名字MyPlayer类。确定后就提示会
在这里插入图片描述
之前创建的是蓝图项目,创建类后就包含源码了,需要关闭UE重新进入。

进入后我们就可以看到自己建立的类了。
在这里插入图片描述
如果你看不到C++Classes,请掉右边的Settings,并勾选Show C++ Classes。
在这里插入图片描述
这里我重新创建了类名BallPlayer,不喜欢之前的MyPlayer的名字,就不附上截图了。

查看新生成的文件

我们用VS打开项目,可以看到.h和.cpp文件,内容如下:

BallPlayer.h

// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "BallPlayer.generated.h"UCLASS()
class MYPROJECT4_API ABallPlayer : public APawn
{GENERATED_BODY()public:// Sets default values for this pawn's propertiesABallPlayer();protected:// Called when the game starts or when spawnedvirtual void BeginPlay() override;public:	// Called every framevirtual void Tick(float DeltaTime) override;// Called to bind functionality to inputvirtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;};

BallPlayer.cpp

// Fill out your copyright notice in the Description page of Project Settings.#include "BallPlayer.h"// Sets default values
ABallPlayer::ABallPlayer()
{// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.PrimaryActorTick.bCanEverTick = true;}// Called when the game starts or when spawned
void ABallPlayer::BeginPlay()
{Super::BeginPlay();}// Called every frame
void ABallPlayer::Tick(float DeltaTime)
{Super::Tick(DeltaTime);}// Called to bind functionality to input
void ABallPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{Super::SetupPlayerInputComponent(PlayerInputComponent);}

UE的类前面自动添加了A字母。继承于APawn。

修改代码

下面我们添加一些代码:
BallPlayer.h文件中添加了三个组件:模型Mesh,弹簧,相机。
Mesh就是我们控制看到的小球(UStaticMeshComponent),弹簧(USpringArmComponent)就是用来控制相机和小球之间的距离,相机(UCameraComponent)就是我们的画面视角。

然后MoveForce和JumpForce是控制的物理力大小。

方法:
MoveRight是用来处理左右移动的
MoveForward是用来处理前后移动的
Jump是跳跃

这里注意下头文件,引用的文件要写在#include "BallPlayer.generated.h"的前面。

// Fill out your copyright notice in the Description page of Project Settings.#pragma once#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "Camera/CameraComponent.h"
#include "GameFramework/SpringArmComponent.h"#include "BallPlayer.generated.h"UCLASS()
class MYPROJECT4_API ABallPlayer : public APawn
{GENERATED_BODY()public:// Sets default values for this pawn's propertiesABallPlayer();protected:// Called when the game starts or when spawnedvirtual void BeginPlay() override;UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")UStaticMeshComponent* MeshMain;UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")USpringArmComponent* SpringArmMain;UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")UCameraComponent* CameraMain;UPROPERTY(EditAnywhere,BlueprintReadWrite)float MoveForce = 500.00f;UPROPERTY(EditAnywhere, BlueprintReadWrite)float JumpForce = 500.00f;public:	// Called every frame//virtual void Tick(float DeltaTime) override;// Called to bind functionality to inputvirtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;void MoveRight(float value);void MoveForward(float value);void Jump();
};

我们再来看CPP文件
构造函数中我们看到创建了Mesh,SpringArm和Camera。
SetupAttachment的作用是设置父对象,例如SprintArm的父对象是Mesh。相机是最子层。

SetupPlayerInputComponent函数中绑定了按键,我们后面再截图上来。
BindAction,BindAxis 分别对应了不同的操作。

当键盘按下的时候,就进入(MoveRight,MoveForward,Jump)3个函数进行前后左右跳跃处理。

// Fill out your copyright notice in the Description page of Project Settings.#include "BallPlayer.h"
#include "Camera/CameraComponent.h"
#include "GameFramework/SpringArmComponent.h"// Sets default values
ABallPlayer::ABallPlayer()
{// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.PrimaryActorTick.bCanEverTick = false;MeshMain = CreateDefaultSubobject<UStaticMeshComponent>("Mesh");SpringArmMain = CreateDefaultSubobject<USpringArmComponent>("SpringArm");CameraMain = CreateDefaultSubobject<UCameraComponent>("Camera");RootComponent = MeshMain;SpringArmMain->SetupAttachment(MeshMain);CameraMain->SetupAttachment(SpringArmMain);MeshMain->SetSimulatePhysics(true);SpringArmMain->bUsePawnControlRotation = true;
}// Called when the game starts or when spawned
void ABallPlayer::BeginPlay()
{Super::BeginPlay();MoveForce *= MeshMain->GetMass();JumpForce *= MeshMain->GetMass();
} Called every frame
//void ABallPlayer::Tick(float DeltaTime)
//{
//	Super::Tick(DeltaTime);
//
//}// Called to bind functionality to input
void ABallPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{Super::SetupPlayerInputComponent(PlayerInputComponent);//映射按键InputComponent->BindAction("Jump", IE_Pressed, this, &ABallPlayer::Jump);InputComponent->BindAxis("MoveForward", this,  &ABallPlayer::MoveForward);InputComponent->BindAxis("MoveRight", this,  &ABallPlayer::MoveRight);
}void ABallPlayer::MoveRight(float value)
{const FVector right = CameraMain->GetRightVector() * MoveForce * value;MeshMain->AddForce(right);
}void ABallPlayer::MoveForward(float value)
{const FVector forward = CameraMain->GetForwardVector() * MoveForce * value;MeshMain->AddForce(forward);
}void ABallPlayer::Jump()
{MeshMain->AddImpulse(FVector(0, 0, JumpForce));
}

键盘的设置

我们打开菜单的编辑Edit 、项目设置Project Settings
在这里插入图片描述
代码编写好后可以按下Ctrl+Alt+F11,进行快速编译。

创建蓝图

我们的代码编译完成后,可以再脚本上右键创建蓝图。
在这里插入图片描述
或者可以再文件夹力点击右键创建蓝图:
在这里插入图片描述
在弹出界面上搜索ballplayer选择确定。
在这里插入图片描述
双击建立好的蓝图BP_BallPlayer,会进入蓝图界面,我们就看到Mesh弹簧和相机的层次结构了。
在这里插入图片描述

设置小球

蓝图里我们点击小球选择一个Mesh
在这里插入图片描述
这里选择的小球Mesh是100*100的。

设置弹簧

在这里插入图片描述
我们关闭几个参数inheritPitch等,按E切换到旋转,然后让相机有一些高度,这样视角舒服一些。

保存蓝图

最后保存蓝图,并点击Compile编译。
在这里插入图片描述

设置玩家

在场景中拖入BP_BallPlayer蓝图,并且设置Pawn里的AutoPossessPlayer的属性选择Player 0。
在这里插入图片描述

运行游戏

请添加图片描述

参考:
https://www.youtube.com/watch?v=KQgOqyYoHAs

http://www.yayakq.cn/news/679302/

相关文章:

  • 网站引导页动态效果怎么做的咸宁网站制作公司
  • 深圳网站的建设酒泉地网站推广
  • 济南市高新技术官方网站开发区网站备案在哪个网
  • 新艾尚网站建设推广西安百度公司电话
  • 银川网站建设哪家价格低wordpress地图在哪
  • 网站建设与发布怎么做网页作业
  • 贵港公司做网站三位效果网站模版
  • 网站备案 内容it培训机构培训多久
  • 全自动网站制作系统在哪个网站可以学做衣服
  • 一流的镇江网站建设可以做代销的网站
  • 环保主题的网站模板百度免费发布信息平台
  • 想做一个自己的网站wordpress有没有付费
  • 东莞皮具网站建设做网站建设比较好的公司
  • 网站建设的功能都需要有哪些dz网站如何搬家
  • 石家庄网站建设高端网站制作教程网站
  • 奢侈品 网站建设方案广东联通通信建设有限公司 网站
  • 科技公司内蒙古网站制作网络服务租赁合同范本
  • 荥阳网站制作全国新冠疫苗接种率
  • 政协网站法治建设版块重庆网约车
  • 手机端网站ui做多少像素网页无法访问是怎么回事
  • 重庆手机网站建设公司对电子商务网站设计的理解
  • 如何制作网页网站淮安网络营销
  • 西安网站建设公司西安网络公司网站建站网站建站
  • 自己做网站买一对一专属定制方案
  • 分享站wordpress主题acfun网站设计改进
  • 触屏手机网站模板app开发
  • 福州市城乡建设发展总公司网站网店怎么开店注册
  • 兴义网站开发福建做网站
  • 网站的站点建设单页网站案例分析
  • 西宁做网站的有吗今天哈尔滨最新通知