Proper way to move Rigidbody GameObject

后端 未结 4 798
说谎
说谎 2020-11-27 23:20

I just started learning Unity. I tried to make a simple box move by using this script. The premise is, whenever someone presses \'w\' the box moves forward.

         


        
4条回答
  •  野性不改
    2020-11-27 23:43

    Instead of making w a bool, you can use axis, also, in unity editor you should make it so the rigidbody movement is frozen

    here is some code

    void update()
    {
        rb.AddForce(Input.GetAxis("Horizontal"));
    }
    

提交回复
热议问题