如何在不限制任何值或使用“.normaized”的情况下保持对角线速度与水平和垂直速度相同。我试图标准化这些值,但我丢失了 1 和 0 之间的操纵杆值。这是我的代码:
void ListenInput()
{
Vector3 rightDirection = camera.right;
Vector3 frontDirection = camera.GetForwardFromAngleY();
move = new Vector2(
Input.GetAxis("Horizontal"),
Input.GetAxis("Vertical")
);
MoveCharacter(rightDirection * move.x);
MoveCharacter(frontDirection * move.y);
}
void MoveCharacter(Vector3 velocity)
{
transform.position += velocity * Time.deltaTime * runningSpeed;
}
Run Code Online (Sandbox Code Playgroud)