【发布时间】:2019-11-06 19:41:58
【问题描述】:
我有一个 3D 游戏,我的相机正在观察我的所有地形,并且我有一个使用 Xbox 控制器移动的角色。我希望我的角色只向它所看的方向移动,而不是向两侧移动。我有下一个让我的角色移动的代码。
void Update()
{
MoveInput = new Vector3(Input.GetAxisRaw("Horizontal"), 0f, Input.GetAxisRaw("Vertical"));
moveVelocity = MoveInput * MoveSpeed;
Vector3 PlayerDirection = Vector3.right * -Input.GetAxisRaw("RHorizontal") + Vector3.forward * -Input.GetAxisRaw("RVertical");
if (PlayerDirection.sqrMagnitude > 0.0f)
{
transform.rotation = Quaternion.LookRotation(PlayerDirection, Vector3.up);
}
角色随着控制器的左侧移动,而右侧则可以移动所面对的方向。
【问题讨论】:
-
您找到解决方案了吗?