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); } } } }

23rd Sep 2017, 5:58 PM
Taylor Hupp
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"))
29th Jan 2019, 7:09 AM
Muhammad Abu Baker
Muhammad Abu Baker - avatar
+ 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
24th Sep 2017, 3:42 PM
Rrestoring faith
Rrestoring faith - avatar