Best way to use Rigidbody.AddForce to fly straight only?

I had no idea how to title that.

Basically, I have a flyer in a 3D environment. In order to take advantage of rigidbody drag and not mess with the physics, I’d like to use AddForce to do movement, since doing so affects the velocity, which is affect by the drag.

However, if I fly straight so my velocity gets up to (0,0,10), and I want to go up, it obviously doesn’t continue on my local Z-axis as I turn, it continues pushing me globally on the Z-axis and new force simply adds to the global Y-axis.

Is it possible to move as if I have an engine in the back pushing me, so as I turn my velocity continues in that direction, constantly on my local Z-axis?

Thanks!

You want to add force in the direction of the front of your plane. So you want to use Transform.forward. Something like:

rigidbody.AddForce(transform.forward * force * Time.deltaTime);  

This way, your plane will be forced forward in the direction it is looking.

Would this not work:

rigidbody.AddRelativeForce(force * Time.deltatime)

From this wiki link, I would say it answers

However, if I fly straight so my velocity gets up to (0,0,10), and I want to go up, it obviously doesn’t continue on my local Z-axis as I turn, it continues pushing me globally on the Z-axis and new force simply adds to the global Y-axis.

I had this same problem concerning flying forward in World Space.

You have to use Transform.TransformDirection function.