加入收藏 | 设为首页 | 会员中心 | 我要投稿 大连站长网 (https://www.0411zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 编程要点 > 语言 > 正文

UE4达成人物跳跃

发布时间:2022-07-16 22:05:36 所属栏目:语言 来源:互联网
导读:这一节我们来实现人物的跳跃。 1) 首先我们打开 UE4 编辑器,点击项目设置,点击输入,添加 BindAction 类型的按键绑定,名字为 Jump,按键是空格键。 2) 在 SetupPlayerInputComponent 函数里面绑定按键输入: void APlayingCharacter::SetupPlayerInputC
  这一节我们来实现人物的跳跃。
 
  1) 首先我们打开 UE4 编辑器,点击项目设置,点击输入,添加 BindAction 类型的按键绑定,名字为 Jump,按键是空格键。
  
  2) 在 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 编辑器点击播放,按空格键人物可以跳跃。

(编辑:大连站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!