I’m a novice on the math calls to make this spaceship to move how I would like it to.
- Spaceship has a rear engine. This increases the velocity in a facing direction.
- Spaceship has rotation thrusters which do not change the forward momentum.
- Space ship has a weaker front engine that decreases the velocity in the facing direction.
- When the space ship turns and fires its rear engines, the vector should change as part of a calculation. So the fastest stop for example would be a 180 degree flip and blast engines. A 90 degree turn will only change the momentum vector a percentage based on physic calc.
Currently I have the force for moving forward working but if I turn I just change direction and my speed continues on the new vector. I tried mucking with rigidbody.AddRelativeForce (Vector3.forward*0.1); but I couldn’t get it working. Any tips on this?
void Update () {
transform.Translate(Vector3.up * Time.deltaTime * speed);
if(Input.GetKey(KeyCode.W)) {
speed += 0.01f;
if (speed > 2.5f)
speed = 2.5f;
}
if(Input.GetKey(KeyCode.S)){
speed -= 0.003f;
if (speed < 0.0f)
speed = 0.0f;
}
if(Input.GetKey(KeyCode.A)) transform.Rotate(0,0,90 * Time.deltaTime);
if(Input.GetKey(KeyCode.D)) transform.Rotate(0,0,-90 * Time.deltaTime);
Vector3 position = transform.position;
}