Help with calculating the forward speed of a plane

Hi,

I’m trying to make a jetplane game so currently I’m making a script for the plane’s movement,problem I have is I don’t know how to calculate the plane’s forward speed,I tried using rigidbody.velocity.z but I think it’s using the global axis rather than the object’s axis which in turn gives me wrong results sadly.

So does anyone know how can I do it?

Thanks in advance.

The velocity is always a vector in worldspace. If you want split the velocity into the 3 local components you can use Transform.InverseTransformDirection:

    // C# / UnityScript
    var localVelocity = transform.InverseTransformDirection(rigidbody.velocity);
    var forwardSpeed = localVelocity.z;