项目结构
资产
- |
|
|
|
Content |
ExternalContent |
Animation |
|
|
Levels |
DefaultMap |
|
|
Player |
Animations |
ABP_BaseCharacter |
|
|
|
BS_Locomotion_Run |
|
|
|
BS_Locomotion_Walk |
|
|
|
BS_Locomotion_Walk_1D |
|
|
BP_STUBaseCharacter |
|
|
|
BP_STUPlayerController |
|
|
BP_STUGameModeBase |
|
|
代码
- |
|
|
|
ShootThemUp |
Public |
Components |
STUCharacterMovementComponent |
|
|
Player |
STUBaseCharacter |
|
|
|
STUPlayerController |
|
STUGameModeBase |
|
|
项目基础设置
- |
载入 ExternalContent/Animation |
创建 DefaultMap 并设置 |
设置地板 |
配置头文件搜索路径 |
添加 PlayerStart |
设置 编译成功自动保存 |
游戏角色
- |
|
C++ |
Player/STUBaseCharacter |
Blueprint |
Player/BP_STUBaseCharacter |
|
Player/Animations/ABP_BaseCharacter |
|
Player/Animations/BS_Locomotion_Run |
|
Player/Animations/BS_Locomotion_Walk |
|
Player/Animations/BS_Locomotion_Walk_1D |
STUBaseCharacter
C++
函数成员
基本函数 |
操作 |
构造函数 |
设置组件类型(初始化列表);初始化组件 |
BeginPlay |
检查组件是否成功创建(check);组件设置;注册委托 |
SetupPlayerInputComponent |
检查组件;绑定平移旋转跳跃跑步键位 |
- 键位绑定
回调函数 |
键位 |
相关函数 |
MoveRight |
左右移动 |
AddMovementInput;GetActorRightVector |
MoveForward |
前后移动 |
AddMovementInput;GetActorForwardVector |
|
左右旋转 |
ACharacter::AddControllerYawInput |
|
上下旋转 |
ACharacter::AddControllerPitchInput |
|
跳跃 |
ACharacter::Jump |
RunEnable,RunDisable |
跑步 |
|
- 接口
接口函数 |
操作 |
GetDirection |
计算前进方向和速度方向的夹角;供ABP_STBaseCharacter使用 |
IsRunning |
判断角色是否满足跑步条件;供STUCharacterMovementComponent使用;供ABP_STBaseCharacter使用 |
数据成员
组件 |
用途 |
SpringArmComponent |
以游戏角色为中心左右旋转 |
CameraComponent |
第三视角 |
CharacterMovementComponent |
运动组件 |
- 标志位
|
说明 |
AbleRun |
跑步键位是否按下 |
IsForward |
向前方向键是否按下 |
Player/BP_STUBaseCharacter
Blueprint
CapsuleComponent
MeshComponent
|
说明 |
Mesh > Skeletal Mesh Asset |
HeroTPP |
Materials > Element 0 |
HeroTPP |
Animation Mode |
UseAnimationBlueprint |
AnimClass |
ABP_BaseCharacter |
SpringArmComponent
|
说明 |
UsePawnControlRotation |
true |
Player/Animations/ABP_BaseCharacter
Blueprint
AnimGraph
-
状态机
- Locomotion作为OutputPose的输入
- 状态
|
状态 |
说明 |
走路 |
Walk |
BS_Locomotion_Walk;混合空间 |
跑步 |
Run |
BS_Locomotion_Run;混合空间1D |
跳跃 |
JumpStart |
|
|
JumpLoop |
|
|
JumpEnd |
|
- 变量
- 动画输入
|
名称 |
速度 |
Velocity |
速度和前进方向的夹角 |
Directon |
- 转换条件
|
|
说明 |
IsRunning |
C++ |
满足3个条件:按下Shift;速度和前进方向夹角为0(或按下W/Up);速度不为0 |
IsFalling |
CharacterMovementComponent::IsFalling |
返回true,意味着游戏角色跳起;接着返回false,意味着游戏角色回到地面 |
EventGraph
设置变量
- |
Velocity |
Directon |
IsRunning |
IsFalling |
组件
C++
STUCharacterMovementComponent
满足跑步条件时,提高运动速度上限
参数 |
说明 |
SpeedAcceleration |
加速系数 |