在Unity中,玩家正在旋转而不是移动。

huangapple go评论70阅读模式
英文:

In Unity Player Is Spinning Instead Of Moving

问题

我试图在Unity中制作一个3D平台游戏,所以我观看了Brackeys的一个教程。在编码部分以使用WASD和箭头键移动玩家后,我进行了测试。但是当我尝试移动时,玩家不是移动,而是原地旋转。这是我使用的代码:

public CharacterController controller;
public float speed = 12f;

void Update() {
    float x = Input.GetAxis("Horizontal");
    float z = Input.GetAxis("Vertical");

    Vector3 move = transform.right * x + transform.forward * z;

    controller.Move(move * speed * Time.deltaTime);
}

我完全不知道为什么会发生这种情况。

英文:

I was trying to make a 3d platformer game in Unity, so I watched one of Brackeys tutorials. After Coding in the part to Move the player with the WASD and Arrow Keys, I tested it out. But when I tried to move, instead the player would spin in place. Here's the code I used:

public CharacterController controller;
public float speed = 12f;

void Update() {
    float x = Input.GetAxis("Horizontal");
    float z = Input.GetAxis("Vertical");

    Vector3 move = transform.right * x + transform.forward * z;

    controller.Move(move * speed * Time.deltaTime);
}

I have absolutely no idea why this is happening.

答案1

得分: 0

"transform" 不是处理移动的正确方式。搜索特定的移动方法,例如 "translate",但这取决于目标和环境。我在三维空间中使用 "rigidbody" 进行移动,并建议您采用相同的方法,因为这是最物理上准确的。还可以在YouTube上搜索教程,这个主题已经被讨论了很多次。

英文:

transform is not really correct way to handle movement. Search for a special movement method for example translate but depends on the target and environment. I make movement in 3d space using rigidbody and recommend doing the same because it is the most physically accurate. Also search for tutorials on youtube, this topic was covered a lot of times there.

huangapple
  • 本文由 发表于 2023年5月7日 07:06:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76191558.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定