英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论