What is the velocity on a given axis of a rigidbody?

I'm looking to find out what the velocity of a rigidbody is on a specified local axis.

I'm building a simulation/shooter based on scifi airship warfare, which includes both planes and floating anti-gravity airships. For the planes, I'd like to get the speed along the z-axis for a simplified calculation of lift. In aerial geek-talk, I'm basically interested in Indicated Airspeed.

For the airships, it will be used to aid calculating collision damage, hopefully in conjunction with a normal-line between the colliding parts. The logic is that fast-front hitting damage will do more than a gentle glancing bump.

Can anyone suggest the most efficient way to do this? I'm really looking for the closest actual equivalent to "rigidbody.GetLocalVelocity(z);"

You could do what the Car tutorial does. To find the local velocity it goes:

function Update () {

    //find the local velocity of the rigidbody.
    var relative : Vector3 = transform.InverseTransformDirection(rigidbody.velocity);
}

or when you use OnCollisionEnter(col : Collision), consider using Collision.RelativeVelocity.

I'm confused. Why can't you just use `Rigidbody.velocity.x/y/z` , or `GetLocalVelocity()`, as you said?

You could also write your own speed calculator, just save the x/y/z position from the previous Update and then subtract it from the current one, which gives you the speed. Something along the lines of:


float lastPos;
float speed;

void FixedUpdate()
{
     speed = Mathf.Abs(lastPos - transform.position.z);
          // or position.x/y if you need that
     lastPos = transform.position.z; // or x/y.
}