|
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);"
(comments are locked)
|
|
You could do what the Car tutorial does. To find the local velocity it goes:
or when you use OnCollisionEnter(col : Collision), consider using Collision.RelativeVelocity. 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
(comments are locked)
|
|
I'm confused. Why can't you just use 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: 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
(comments are locked)
|
