0
I'm following (Brackeys) on YouTube, and I can get my object to go forwarde but it's not going sideways. Dose he do good codes?
unity UnityEngine; public class move : MonoBehaviour{ public Rigidbody rb; void FixedUpdate () { rb.AddForce (500, 0, 0 * Time.deltaTime); if (input.GetKey (KeyCode.A)) { rb.AddForce(0, 0, -500 * Time.deltaTime); if (Input.GetKey (KeyCode.D)) { rb.AddForce (0, 0, 500 * Time.deltaTime); } } } }
2 ответов
+ 3
You should specify the event if it's pressing the button stopping
if(input.GetKeyDown(KeyCode.A))
Or you can use
if(input.GetKey("a"))
+ 2
Instead of adding a force to the rigidbody, It sounds like what you want is changing the velocity. Try:
rb.velocity = // the code here