Change direction of rigidbody when force is no longer being applied

Hi,

I’m creating a basic spaceship style movement system and and am moving the object using AddForce applied to its Rigidbody when a ‘thrust’ key is held down. The direction of the force is based on the forward direction of its camera, in First Person which is controlled by the mouse (i.e. it moves in the direction it is looking). The force is only applied when the thrust key is pressed down, which means that if the mouse is moved around after the key is released, the ship will continue to move in the direction in which the force was applied, not where it is currently looking.
In basic terms:

shipRB.AddForce(cameraTrans.forward * ThrustSpeed); 

I was wondering how I might be able to change the direction of the Rigidbody and have it turn/rotate and continue to move in the direction the camera is looking in, even when the key has been released.

Any help would be great - thanks in advance.

2 Answers

2

In your Update, you could try checking if the rigidbody’s magnitude is less then your thrust speed.
if(shipRB.velocity.magnitude <= ThrustSpeed){//make magic happen}

Hi Dibbie - thanks for the suggestion!

But what is the magic that I need to happen to make the Rigidbody move in the direction that the camera’s forward is pointing in after a force has been applied? :smiley: