In this video notice how the player thrusts in one direction and must either reverse, or turn around and thrust in the opposite direction, to change the player’s direction. Similar to actual space physics. There’s no drag to slow the player’s movement and unless the player hits something they’re gonna keep on moving. How can I implement this in my own player environment? What components, what kind of scripts do I need? I’m a Unity beginner but I know some C#, your help will help me get started on the right track. Thank you.
If it helps this is the code I have so far for my player controller:
public class Movement : MonoBehaviour {
public float thrust;
public float rotationSpeed;
public Rigidbody rb;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody> ();
}
// Update is called once per frame
void Update () {
float moveX = Input.GetAxis ("Horizontal") * thrust;
float moveZ = Input.GetAxis ("Vertical") * thrust;
rb.freezeRotation = true;
//rb.AddForce (0, 0, moveZ);
rb.AddRelativeForce (Vector3.forward * moveZ);
if (Input.GetKey (KeyCode.A))
transform.Rotate (-Vector3.up * rotationSpeed * Time.deltaTime);
else if (Input.GetKey (KeyCode.D))
transform.Rotate (Vector3.up * rotationSpeed * Time.deltaTime);
//rb.AddRelativeForce(Vector3.right * moveX * thrust);
}
}