概览
|
|
举例 |
轴映射 |
连续 |
前后左右移动 |
动作映射 |
离散 |
跳跃,装弹,更换武器 |
绑定移动键位
虚幻编辑器
项目设置 > Engine > Input
轴映射
函数描述 |
键位 |
Scale |
MoveRight |
Left/A |
-1 |
|
Right/D |
1 |
MoveForward |
Up/W |
1 |
|
Down/S |
-1 |
实现前后左右移动逻辑
C++
- |
回调函数签名 |
BindAxis |
void handler(float Amount) |
函数描述 |
回调函数 |
方向 |
输入处理 |
MoveForward |
MoveForward |
GetActorForwardVector |
AddMovementInput |
MoveRight |
MoveRight |
GetActorRightVector |
AddMovementInput |
- 实现回调函数
ShootThemUp: Player/STUBaseCharacter.cpp
1#include "Components/InputComponent.h"
2
3void ASTUBaseCharacter::MoveForward(float Amount)
4{
5 AddMovementInput(GetActorForwardVector(), Amount);
6}
7
8void ASTUBaseCharacter::MoveRight(float Amount)
9{
10 AddMovementInput(GetActorRightVector(), Amount);
11}
- 绑定到函数描述
ShootThemUp: Player/STUBaseCharacter.cpp
1// SetupPlayerInputComponent
2PlayerInputComponent->BindAxis("MoveForward", this, &ASTUBaseCharacter::MoveForward);
3PlayerInputComponent->BindAxis("MoveRight", this, &ASTUBaseCharacter::MoveRight);
- 添加函数声明
ShootThemUp: Player/STUBaseCharacter.h
- 编译ShootThemUp