UE4 C++ Character动作映射
来源:互联网 发布:catdrawing转换cad软件 编辑:程序博客网 时间:2024/05/29 10:08
1. 首先在项目设置中,映射按键
2. 在character的头文件中,声明添加映射按键相应的函数。
其中character的基类中,已经定义了关于鼠标的旋转等相关函数(AddControllerYawInput、AddControllerPitchInput),在头文件中可以不用声明
UFUNCTION()void MoveForward(float value);UFUNCTION()void MoveRight(float value);UFUNCTION()void StartJump();UFUNCTION()void StopJump();
3. 在character源文件中,定义声明的函数
void AFPSCharacter::MoveForward(float value){// 明确哪个方向是“前进”,并记录玩家试图向此方向移动。FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::X);AddMovementInput(Direction, value);}void AFPSCharacter::MoveRight(float value){// 明确哪个方向是“向右”,并记录玩家试图向此方向移动。FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::Y);AddMovementInput(Direction, value);}//Character 基类内置的角色跳跃支持。角色跳跃与 bPressedJump 变量绑定。因此需要执行的操作是在按下跳跃动作时将该布尔型设为 true,松开跳跃动作时设为 false。void AFPSCharacter::StartJump(){ bPressedJump = true;}void AFPSCharacter::StopJump(){bPressedJump = false;}
4. 绑定映射
void AFPSCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent){Super::SetupPlayerInputComponent(PlayerInputComponent);//跳跃绑定InputComponent->BindAction("Jump", IE_Pressed, this, &AFPSCharacter::StartJump);InputComponent->BindAction("Jump", IE_Released, this, &AFPSCharacter::StopJump);// 设置“移动”绑定。InputComponent->BindAxis("MoveForward", this, &AFPSCharacter::MoveForward);InputComponent->BindAxis("MoveRight", this, &AFPSCharacter::MoveRight);InputComponent->BindAxis("Turn", this, &AFPSCharacter::AddControllerYawInput);InputComponent->BindAxis("LookUp", this, &AFPSCharacter::AddControllerPitchInput);}
5. 在定义移动函数时,也可按如下方式定义,看起来好理解些
void AMyThirdCharacter::MoveForward(float value) { if ((Controller != NULL) && (value != 0.0f)) { // 找到当前的前方向 const FRotator Rotation = Controller->GetControlRotation(); const FRotator YawRotation(0, Rotation.Yaw, 0); // 获取到前方向 const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X); AddMovementInput(Direction, value); } }
0 0
- UE4 C++ Character动作映射
- UE4 Character旋转
- ue4 character 物理测试
- UE4动作流程总结
- 【UE4/C++】切换镜头
- 虚拟现实-VR-UE4-创建一个自定义的角色 Character
- 虚拟现实-VR-UE4-编辑自定义Character-上下左右移动-旋转
- UE4中的 Pawn、Character、Controller、Player Controller是什么?
- C------character counting
- C. K-Dominant Character
- UE4中的单映射:TMap容器
- UE4中的单映射:TMap容器
- UE4 C++ 动态数组和映射操作
- ue4中的路径动画和动作混合初探笔记
- ue4中的路径动画和动作混合初探笔记
- C#merlin动作
- wincc常用C动作
- 【UE4/C++】宏的使用
- webstorm用npm运行任务快捷方式(即显示npm任务面板)
- [CURL] -- PHP使用CURL详解
- SQL 模糊查询
- vim的查找字符串
- 动态规划leetcode 回顾
- UE4 C++ Character动作映射
- 解决Cannot change version of project facet Dynamic web module to 2.5
- 数据结构实验之链表三:链表的逆置
- 热释电红外传感器原理和应用
- Java基础之集合
- url
- JavaScript常用对象
- Linux中profile、bashrc、bash_profile之间的区别和联系
- 五分钟带你了解CPU、指令、主存与硬盘之间的关系