c语言人物跳跃游戏,UE4实现人物跳跃

这一节我们来实现人物的跳跃。

1) 首先我们打开 UE4 编辑器,点击项目设置,点击输入,添加 BindAction 类型的按键绑定,名字为 Jump,按键是空格键。

81d3541d68378cb6d12a3b1849eb3fd0.gif

2) 打开 VS 编辑器,在我们的角色类 APlayingCharacter 头文件的末尾声明两个函数,分别是开始跳跃和停止跳跃:

//跳跃开始

void JumpStart();

//跳跃结束

void JumpEnd();

3) APlayingCharacter.cpp 实现如下:

void APlayingCharacter::JumpStart()

{

//如果是真的话,角色跳跃

bPressedJump = true;

}

void APlayingCharacter::JumpEnd()

{

//如果是假的话,结束跳跃

bPressedJump = false;

}

4) 在 SetupPlayerInputComponent 函数里面绑定按键输入:

void APlayingCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)

{

Super::SetupPlayerInputComponent(PlayerInputComponent);

InputComponent->BindAxis("MoveForward",this, &APlayingCharacter::MoveForward);

InputComponent->BindAxis("MoveBack",this, &APlayingCharacter::MoveBack);

InputComponent->BindAxis("MoveRight",this, &APlayingCharacter::MoveRight);

InputComponent->BindAxis("MoveLeft",this, &APlayingCharacter::MoveLeft);

InputComponent->BindAxis("Turn", his, &APawn::AddControllerYawInput);

InputComponent->BindAxis("LookUp",this, &APawn::AddControllerPitchInput);

InputComponent->BindAction("Jump",IE_Pressed,this,&APlayingCharacter::JumpStart);

InputComponent->BindAction("Jump", IE_Released, this, &APlayingCharacter::JumpEnd);

}

BindAction 是一种 “状态”按键输入类,IE_Pressed 表示的是按下的时候执行JumpStart() 函数,IE_Released 表示的是松开的时候执行JumpEnd()事件。BindAxis 按键绑定类型是可以一直按一直执行的,而 BindAction 是按一次执行一次事件。松开执行一次事件,BindAction也可以不配套使用。

5) 编译,打开 UE4 编辑器点击播放,按空格键人物可以跳跃。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值