- Home /
How do I obtain an object's local Z velocity?
I am trying to get my car's velocity, so that I can adjust the steering sensitivity dynamically. No matter what I do, it returns the GLOBAL velocity, which doesn't help me at all.
This:
LocalVelocity = transform.InverseTransformDirection(PlayerCar.rigidbody.velocity).z;
returns the exact same output as this:
LocalVelocity = PlayerCar.rigidbody.velocity.z;
Why is this not converting it to local?I thought that's what the InverseTransformDirection did?!?!
I have tried applying it to just the z axis (as above) and also the the whole Vector3... both results are identical.
velocity.magnitude seems to be working for what I need but I'd still like to know why this wasn't working...
Answer by MakeCodeNow · Jun 23, 2014 at 06:05 PM
I think the problem is that you are using your own transform, not the PhysicsCar transform. It should be:
LocalVelocity = PlayerCar.transform.InverseTransformDirection(PlayerCar.rigidbody.velocity).z;
You are correct. I am an idiot. Can't believe I didn't notice that! lol. Too many late nights ;)