hey i need to know how to find the angle between two different points. For example if i had two different points pointA and pointB how would i find the global rotation required for pointA to face pointB. Thanks.
A point doesn't have an orientation, so a point can't "face" another point. If you want to make your GameObject face a certain point you can use transform.LookAt() to get the angle between two Vectors (not points) you can use Vector3.Angle()
EDIT: To get a ray from point A in the direction of point B you can use point A as origin and (pointB - pointA).normalized as the direction.
Speaking in general math/physics , without to much knowledge of how unity scripting supports the "getters" of this information I may be able to give you the information that you will need. How to get that information is tricky for me at the moment and I will have to direct you "HERE": http://unity3d.com/support/documentation/ScriptReference/index.html for that but I will try giving you some potential candidates to clear up search time, just excuse my lack of testing these idea's.
First of all there are 2 objects here.
Your object A and you Object B.
You want object A to look at Object B if I interpreted your question corrrectly , if not than I should have assumed you want to copy the rotation of object B onto Object A making them both face the same direction. To do that simply get transform.rotation information stored into a variable and create a new rotation quaternion for the A object with the following code sample.
Code for assumption 2 in which you want to copy the rotation of B to A:
This may not work in C# though due to writing permissions on transforms requiring a new keyword in which you create a new (in this case) struct.
This quote from the Unity3D scripting references site explains why you don't want to go into details with Quaternions and simply want to copy paste:
Excuse me if this sample will not work I haven't had the time to test it, but I hope it will be enough to get yon on your way!
If indeed you want to LOOK at the object instead of copy the rotation you would need to do this:
Assumption 1 sample:
Get the location of the target (transform of position B) Use the transform.LookAt member
Hope this is enough information for you to deal with the problem. It's not a great answer I know. But please help yourself to quick answers by adding information such as: Target platform, Compiler, code language used or any other information that can narrow down the search scope for the answer you need.
answered Nov 02 '10 at 09:46 AM