【发布时间】:2021-04-28 00:22:32
【问题描述】:
我需要帮助来统一我的对角线运动。它对角线的速度比水平或垂直的快。
我正在开发一款等距 3D 游戏。我正在使用 Unity 2019.4
这是我的代码:
if (canMove)
{
Vector3 direction = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
Vector3 rightMovement = right * moveSpeed * Time.deltaTime * Input.GetAxis("Horizontal");
Vector3 upMovement = forward.normalized * moveSpeed * Time.deltaTime * Input.GetAxis("Vertical");
Vector3 heading = Vector3.Normalize(rightMovement + upMovement);
transform.forward = heading;
transform.position += rightMovement;
transform.position += upMovement;
}
【问题讨论】:
-
我对 Unity 不是很熟悉,但只是查看您的代码,我发现您将
forward标准化以计算upMovement而不是right的rightMovement。 -
您只需要考虑到对角线移动大约是.77 对于您移动的每个水平和垂直方向。像素是正方形的,因此这会产生对角线移动速度更快的外观,因为像素对角线的长度比水平或垂直方向的长。我不知道为什么你有这么多变量。我认为您只需将方向添加到您的位置即可。
-
Vector3.Normalize(rightMovement + upMovement).normalized你的报酬是按你标准化向量的次数来计算的吗? -
盲人。 Lmaoo。我什至没有意识到我已经把它标准化了两次。