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

 0 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);" more ▼ asked May 20 '10 at 11:12 PM Novodantis 1 1.7k ● 14 ● 22 ● 40 SisterKy 2.4k ● 33 ● 41 ● 59 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

 0 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. more ▼ answered May 21 '10 at 01:33 AM Peter G 15k ● 16 ● 44 ● 136 Aha, I shall try this at the first opportunity, I think it's just what I'm looking for. And Collision.RelativeVelocity was not something I was aware of either; thanks for that! That will make the airship part of the problem vastly simpler. May 21 '10 at 09:34 AM Novodantis 1 Works perfectly. Thanks! May 21 '10 at 10:43 AM Novodantis 1 Thank you, this works as described. Jul 25 '12 at 12:40 AM XaeroDegreaz add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users
 0 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. }`````` more ▼ answered May 20 '10 at 11:49 PM qJake 11.6k ● 43 ● 78 ● 161 rigidbody doesn't have a GetLocalVelocity method, but if it did it would be exactly what I'm looking for. Apologies for confusion. -- rigidbody.velocity.x/y/z is in world space. I'm looking to know the objects speed relative to it's own axis. May 21 '10 at 09:19 AM Novodantis 1 What do you mean relative to its own axis? A game object only has local coordinates if it has a parent object...? May 21 '10 at 10:01 PM qJake All objects have their own co-ordinate space, this is effectively what a Transform is. The 'local' coordinates for positioning a child object are in fact it's position in the parents coordinate space. And the reason I need this forward speed is because airflow only provides lift when passing over the wings in the direction of the centre line (z axis of the aircraft). The same amount of movement in a vertical direction (for example) would not produce lift. May 22 '10 at 06:18 PM Novodantis 1 Right, but you still need to get the global velocity of the entire plane, the wings don't move independently of the plane, they're attached, so even though you need the Z-velocity, it needs to be the global velocity. I'm pretty sure Rigidbody.velocity.z is what you need. May 22 '10 at 08:28 PM qJake I did try to use Rigidbody.velocity.z, before I realised it was in global terms. Global z is essentially your movement 'north/south' right? (to avoid confusion of what I mean here) If you were to head 'east', your global z coord won't change. So your speed readout would be zero. Zero in the north/south direction, yes, but this is not what I needed. I needed the speed along the forward/back axis of the aircraft, not the world, which is what the above car tutorial snippet gives =) May 25 '10 at 06:57 PM Novodantis 1 add new comment (comments are locked) 10|3000 characters needed characters left ▼ Viewable by all users

By Email:

Topics:

x1880
x1797
x318
x68

asked: May 20 '10 at 11:12 PM

Seen: 2429 times

Last Updated: Jul 25 '12 at 12:40 AM