按键映射(Action Mappings)连续性
轴映射(Axis Mappings)间歇性
*按键映射在Setting中完成,在代码中进行绑定;*
轴映射需要有对应函数,在pawn类中进行处理即可
.h
private:
void MoveForward(float Value);
void MoveRight(float Value);
用小扳手直接在cpp文件中生成对应的函数
按键映射(Action Mappings)连续性
轴映射(Axis Mappings)间歇性
*按键映射在Setting中完成,在代码中进行绑定;*
轴映射需要有对应函数,在pawn类中进行处理即可
.h
private:
void MoveForward(float Value);
void MoveRight(float Value);
用小扳手直接在cpp文件中生成对应的函数
releative相对位置
FMath 与平台有关的数学运算
一般用FMath::xxx
设置物体初始位置
.h文件中做声明
UPROPERTY(EditInstanceOnly,Category="My Actor Properties")
FVector InitLocation;
.cpp中实现
InitLocation=FVector(0.0f);
SetActorLocation(InitLocation)
新学到的蓝图宏:EditInstanceOnly
只能在视口界面的面板中编辑物体的位置,不能在蓝图类中编辑
课时15 变换工具
W平移 E旋转 R缩放
如何控制每次物体移动的量?
答:调整视口右上角从左数第一个数值,取消捕捉移动也行
如何让摄像机以我们要移动的物体为参考系?
答:移动物体时按住shift键
UPROPERTY();的宏参数
EditInstanceOnly 只能在实例中设置
VisibleInstanceOnly 只能在实例中可见
EditDefaultsOnly 只能在蓝图类中设置
VisibleDefaultsOnly 只能在蓝图类中可见
EditAnywhere 任何地方可设置
VisibleAnywhere 任何地方可见
ue4单位 1 等于现实生活一厘米
.h是写声明的
.cpp是写逻辑的
Blueprintable(蓝图继承)
EditInstanceOnly
SetActorLocation(FVector(0.0f));
UCLASS(Blueprintable)
这一节课废话有点多,不知道什么时候不如正题
蓝图和C++丽影
UCLASS
UPROPERTY
UFUNCTION
1. cast 投射/转换 可以将子类3的父类指针投射为子类一的指针,然后调用
重要!
//
在#include"XXXX.generated.h"之后不要再include任何东西
//
UHT是什么
511
1.打开使用控制器的旋转:
//Z轴方向的旋转,左右旋转
bUseControllerRotationYaw=true;
2.在Tick函数中添加:
AddControllerYawInpout(MouseInput.X);
510
1.添加按键映射:
LookUp:MouseY
LookRight:MouseX
2.在头文件中声明:
void LookUp(float Value);
void LookRight(float Value);
FVector2D MouseInput;
3.在源文件中实现:
//按键映射绑定
PlayerInputComponent->BindAxis(TEXT("LookUp"),this,&AMyPawn::LookUp);
PlayerInputComponent->BindAxis(TEXT("LookRight"),this,&AMyPawn::LookRight);
//实现
void AMyPawn::LookUp(float Value){
MouseInput.Y=FMath::Clamp(Value,-1.0f,1.0f);
}
void AMyPawn::LookRight(float Value){
MouseInput.X=FMath::Clamp(Value,-1.0f,1.0f);
}
//在Tick函数中:
FRotator NewSpringArmRotation = MySpringArm->GetComponentRotation();
NewSpringArmRotation.Pitch=FMath::Clamp(NewSpringArmRotation.Pitch+=MouseInput.Y,-80.0f,0.0f);
MySpringArm->SetWorldRotator(NewSpringArmRotation);
508
1.优化代码,设置get方法:
//FORCEINLINE是UE中的一个宏,用于优化,用在get/set方法之前或者方法体中只有一条return语句
FORCEINLINE UStaticMeshComponent* GetStaticMeshComponent(){return MyStaticMesh;}
FORCEINLINE USpringArmComponent* GetSpringArmComponent(){return MySpringArm;}
2.在CPP中替换上述两个方法
3.加载静态网格、材质文件:
#include "UObject/ConstructorHelpers.h"
//其中的XXX为在content brower中找到对应的网格模型和材质的文件,选中点击右键拷贝他们的文件引用路径
static ConstructorHelpers::FObjectFinder<UStaticMesh>StaticMeshAsset(TEXT("xxx"));
static ConstructorHelpers::FObjectFinder<UMaterialInterface>MaterialAsset(TEXT("xxx"));
if(StaticMeshAsset.Succeeded() && MaterialAsset.Succeeded()){
MyStaticMesh->SetStaticMesh(StaticMeshAsset.Object);
MyStaticMesh->SetMaterial(0,MaterialAsset.Object);
MyStaticMesh->SetWorldScale3D(FVector(0.5f));
}
507
1.在MyPawn.h中添加弹簧臂组件声明:
public:
UPROPERTY(VisibleAnywhere,Category="My Pawn Components")
class USpringArmComponent* MySpringArm;
2.在MyPawn.cpp中包含头文件:
#include "GameFramework/SpringArmComponent.h"
3.在MyPawn.cpp中添加:
MySpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("MySpringArm"));
MySpringArm ->SetupAttachment(MyStaticMesh);
MySpringArm ->RelativeRotation = FRotator(-45.0f,0.0f,0.0f);
MySpringArm ->TargetArmLength=400.f;
MySpringArm ->bEnableCameraLag=true;
MySpringArm ->CameraLagSpeed=3.0f;
4.注释掉摄像机设置位置和旋转的代码
5.将摄像机附着到弹簧臂组件上:
MyCamera->SetupAttachment(MySpringArm);
506
1.deltatime:两帧之间的时间(屏幕刷新时间),根据电脑的性能决定,高配置的电脑小,低配置的电脑大
两个玩家,假设Tick中增量1单位:
P1 10FPS,deltatime=1/10=0.1s
P2 5FPS,deltatime=1/5 = 0.2s
不使用deltatime:
P1 10*1=10,1秒内移动了10个单位
P2 5*1= 5,1秒内移动了 5个单位
使用deltatime:
P1 10*1*0.1=1,1秒内移动了1个单位
P2 5*1*0.2=1,1秒内移动了1个单位
根据上述比较结果可以看出,deltatime用于解决不同玩家因为电脑性能不同导致游戏中的物体在同一段时间内移动的距离不一样的问题
2.按键~调出控制台,输入t.MaxFPS 10可以调节FPS的值