UE4笔记 之 bOrientRotationToMovement
是蛋黄蛋
编辑于 2022年10月26日 18:12

官方文档:

If true, rotate the Character toward the direction of acceleration, using RotationRate as the rate of rotation change. Overrides UseControllerDesiredRotation. Normally you will want to make sure that other settings are cleared, such as bUseControllerRotationYaw on the Character.

机翻则是:

如果为true,则使用RotationRate作为旋转更改的速率,向加速度方向旋转角色。覆盖UseControllerDesiredRotation。通常,您需要确保清除其他设置,例如角色上的bUseControllerRotationYaw。

如果为true,旋转玩家朝向加速方向

false 为不旋转

代码块
C++
自动换行
复制代码
void ATPSCharacter::Aim_Start() {
	bAim = true;
	bUseControllerRotationYaw = true;
  GetCharacterMovement()->bOrientRotationToMovement = false;
}
复制成功

举例 在TPS(第三人称)游戏中,我设定bAim为true 举枪射击,bUseControllerRotationYaw为真,则我可以按s后退 这时我们需要将bOrientRotationToMovement设置为false,即不旋转玩家朝向后转身 我瞄准时肯定要保持朝向射击方向

代码块
C++
自动换行
复制代码
void ATPSCharacter::Aim_End() {
	bAim = false;
	bUseControllerRotationYaw = false;
	GetCharacterMovement()->bOrientRotationToMovement = true;
}
复制成功

Aim_End 放弃瞄准,这时则后退玩家朝向改变

需牢记 若使用 二者 则bUseControllerRotationYaw 与 bOrientRotationToMovement 布尔值要相反