- Home /
Angle between 2 vectors/points on a local axis
I'm scripting a cartoon style car (which is why I'm not using wheel colliders) and need to find the angle between the front axle and back axle from the side and from the top (and eventually back) so I can set the cars pitch and yaw.
This is my first 3D game so I've not quite learnt all the handy maths yet. Usually I would use Atan2 in 2D but obviously I can't use it here because as soon as the car turns the axis I use is wrong.
Thanks
I am not sure if this is the answer to your question, but to find the smallest angle between any two vectors you can use Vector3.Angle
(see: http://docs.unity3d.com/Documentation/ScriptReference/Vector3.Angle.html)
That is something I looked at but it only returns (as far as I know) an angle but not a direction i.e. 5 degrees not 5 degrees to the right.
Answer by aldonaletto · Jan 26, 2013 at 03:18 PM
If you want to align the vehicle to the ground, take a look at this question - my answer gets the ground normal and aligns the vehicle (which is a CharacterController) to it.
I was going to do something like this as my plan B if I couldn't get what I'm doing working. At the moment I'm essentially doing a 3D version of this http://engineeringdotnet.blogspot.co.uk/2010/04/simple-2d-car-physics-in-games.html