|
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.
(comments are locked)
|
|
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. Thanks for the responses and sorry if i was vague with the information. More specifically i wanted to create a ray that points from its origin to another object and i wanted to know how to go about getting the direction for the ray that is required when constructing the ray.
Nov 03 '10 at 06:18 AM
Gian Hancock
I edited my original answer.
Nov 03 '10 at 08:21 AM
StephanK
Thanks for the help everything works fine now, although i don't understand mathematically how normalizing the difference between to vectors gives the direction, but i guess that is extra information i don't need to know anyway :p. Thanks again for the help.
Nov 03 '10 at 10:23 AM
Gian Hancock
Well it maybe an extra information, but it's a useful one. Vectors have a direction and a length(magnitude). A direction is a so called unit vector, which has a length of 1. Normalizing a vector will give you its direction. Mathematically it divides the vector by its magnitude returnin a vector of length 1.
Nov 03 '10 at 03:49 PM
StephanK
interesting, so if i have a vector of [1,1,1] its magnitude is is 1.7 and its normalized version is [1/1.7, 1-1.7, 1/1.7] or [.588,588,588]?. if i am correct so far, how would i go about converting this into a Euler or something more useful then just a vector?
Nov 04 '10 at 06:31 AM
Gian Hancock
(comments are locked)
|
|
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.
(comments are locked)
|
