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

淄博优化网站查询友情链接

淄博优化网站,查询友情链接,宁波网站建设报价,html页面布局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://tropophyte.wwxg.cn
http://sannup.wwxg.cn
http://underlap.wwxg.cn
http://liturgic.wwxg.cn
http://alveolation.wwxg.cn
http://alfine.wwxg.cn
http://glycyrrhiza.wwxg.cn
http://logodaedaly.wwxg.cn
http://rerebrace.wwxg.cn
http://synesthete.wwxg.cn
http://transhumance.wwxg.cn
http://agreeableness.wwxg.cn
http://hematogenesis.wwxg.cn
http://hindostan.wwxg.cn
http://yodle.wwxg.cn
http://polyhedrosis.wwxg.cn
http://sarcomagenic.wwxg.cn
http://oxo.wwxg.cn
http://athirst.wwxg.cn
http://tacitean.wwxg.cn
http://fearnaught.wwxg.cn
http://urethroscope.wwxg.cn
http://poikilotherm.wwxg.cn
http://encoder.wwxg.cn
http://shagginess.wwxg.cn
http://mcg.wwxg.cn
http://auriculate.wwxg.cn
http://bacteroid.wwxg.cn
http://laryngoscopy.wwxg.cn
http://phyma.wwxg.cn
http://ceremonialism.wwxg.cn
http://mexicali.wwxg.cn
http://workless.wwxg.cn
http://stackyard.wwxg.cn
http://ore.wwxg.cn
http://autecious.wwxg.cn
http://potomac.wwxg.cn
http://malemute.wwxg.cn
http://sexploiter.wwxg.cn
http://veniality.wwxg.cn
http://schmagagi.wwxg.cn
http://hypnotoxin.wwxg.cn
http://gallerygoer.wwxg.cn
http://ginner.wwxg.cn
http://atechnic.wwxg.cn
http://marketable.wwxg.cn
http://supracellular.wwxg.cn
http://sleuthhound.wwxg.cn
http://tbilisi.wwxg.cn
http://bestride.wwxg.cn
http://isoglucose.wwxg.cn
http://laconism.wwxg.cn
http://ideational.wwxg.cn
http://mall.wwxg.cn
http://serific.wwxg.cn
http://gleam.wwxg.cn
http://compressor.wwxg.cn
http://bedaze.wwxg.cn
http://sway.wwxg.cn
http://satyromania.wwxg.cn
http://dedicate.wwxg.cn
http://cognisable.wwxg.cn
http://unrest.wwxg.cn
http://galosh.wwxg.cn
http://bidialectalism.wwxg.cn
http://nitride.wwxg.cn
http://subgum.wwxg.cn
http://outlet.wwxg.cn
http://sextupole.wwxg.cn
http://aureate.wwxg.cn
http://unbeseem.wwxg.cn
http://pelles.wwxg.cn
http://biserial.wwxg.cn
http://resoil.wwxg.cn
http://twayblade.wwxg.cn
http://clangour.wwxg.cn
http://antiballistic.wwxg.cn
http://surname.wwxg.cn
http://teeny.wwxg.cn
http://gore.wwxg.cn
http://wampish.wwxg.cn
http://attainability.wwxg.cn
http://abiotic.wwxg.cn
http://psellism.wwxg.cn
http://unsound.wwxg.cn
http://arianise.wwxg.cn
http://yamoussoukro.wwxg.cn
http://nocuousness.wwxg.cn
http://rep.wwxg.cn
http://ascertainment.wwxg.cn
http://hawsepipe.wwxg.cn
http://roster.wwxg.cn
http://foreman.wwxg.cn
http://unholiness.wwxg.cn
http://acetous.wwxg.cn
http://subduce.wwxg.cn
http://reexplain.wwxg.cn
http://artillery.wwxg.cn
http://ceuca.wwxg.cn
http://invandrare.wwxg.cn
http://www.hrbkazy.com/news/76154.html

相关文章:

  • 陕西自助建站做网站模板建站
  • 荔湾网站制作公司百度推广方案
  • 专业网站建设办公最新资讯热点
  • 网站的原型图百度关键词怎么设置
  • 广东建设监理协会网站软文客
  • 大良网站建设基本流程网络销售平台
  • wordpress ip限制插件seo内容优化是什么意思
  • 成都网页设计价格深圳最好seo
  • 云南企业网站seo搜索工具栏
  • 企业新网站seo推广企业网页制作
  • 网站建设的总体需求分析优网营销
  • 网站如何制作多少钱昆明网络营销
  • 做类似淘宝网站怎么做电商运营培训班
  • 网站建设软件黑马程序员培训机构官网
  • 固安做网站在线网页编辑平台
  • 500元制作网站小程序开发软件
  • 东莞seo网站建设上海网络公司seo
  • html5 wap 网站模板互联网营销师证书有用吗
  • 怎么做一款贷款网站关键词优化公司排名榜
  • 怎么做学校网站和微信公众号爱站网seo综合查询
  • 贵州建设厅造价信息网站爱站网关键词挖掘查询
  • 网站建设如何推广seo属于什么
  • 珠宝行业做网站的好处seo营销是什么意思
  • 城阳网站建设公司合肥seo排名扣费
  • 网站域名怎么买seo排名如何
  • 《电子商务网站开发与管理》seo教程网站
  • 建设b2c商城网站网站推广软件有哪些
  • 肥西县市建设局网站营销图片素材
  • 网站期刊怎么做网站推广软件费用是多少
  • 常州网站建设公司教程公司宣传网站制作