|
I'm creating a simple driving game were the player controlled vehicle is a single box-like rigid body. I am accelerating the vehicle with rigid.body.AddRelativeForce and I'm steering the object with rigid.body.MoveRotation. I really need to be able to obtain the relative velocity along the vehicles local X axis (forwards and backwards) to be able to script rules and logic from, and right now all I seem able to do is get either the world velocity (rigidbody.velocity) or all-axis-combined velocity (rigidbody.velocity.magnitude) but neither of these are accurate enough for what I want to do. Can anyone offer any hints here? Thanks.
(comments are locked)
|
|
Try (untested): Just tested it, it works -- I've been doing this manually all this time. Thanks!
Nov 02 '10 at 04:08 PM
VS48
That does exactly the same as the code I posted... (which works btw, just tested)
Nov 02 '10 at 04:10 PM
Atnas1010
I don't seem to be getting the same result
Nov 02 '10 at 04:30 PM
VS48
Hmm, I'm looking into that right now
Nov 02 '10 at 04:38 PM
Atnas1010
Hehehe this should work: Quaternion.FromToRotation(transform.forward, Vector3.forward) * rigidbody.velocity); It was correct, just I think one of the axes was inverted
Nov 02 '10 at 04:50 PM
VS48
(comments are locked)
|
|
Is this what you are looking for? (transform.rotation * rigidbody.velocity).x
(comments are locked)
|
|
Use No, rigidbody.velocity.x gives me the velocity on the world x axis, not the local axis - this means it can report anything from high to low values depending on the direction I'm driving the vehicle in.
Nov 02 '10 at 02:06 PM
Alkan
(comments are locked)
|
