Hi I’m coming from another engine and try to solve a more or less simple problem:
I have 2 points (as Vector3) and one other Vector3 that points into a certain direction. Now I want to rotate those
2 points around the Vector3 so that they are aligned to its direction.
See this image for more explainations:
My problem is, that I don’t know the angle in which the directional Vector3 is pointing. Can anybody
give me a hint on how to proceed here? Thanks!
uy
November 3, 2013, 9:05am
2
I’m not 100% sure what you’re asking. Are you asking how you would set the directional angle?
If you are wondering how to make an object look at another, then use LookAt
the syntax is:
objectIWantToMove.transform.LookAt(objectToLookAt);
Documentation here Unity - Scripting API: Transform.LookAt
I think this is what you are asking. If not, just reply and I’ll try to answer.
hpjohn
November 3, 2013, 12:30pm
3
Assuming this is all taking place on the x and y axes (swap the y and z components if its x and z, etc)
Known values are A, B, and the desired v3:
Vector3 v2 = ( A + B ) / 2;
Vector3 AB = B - A;
Vector3 v1 = new Vector3( -AB.y, AB.x, 0 );
float r = Vector3.Angle( v1, v3 );
Quaternion rot = Quaternion.Euler(0,0,r);
Vector3 P1 = rot * ( A - v2 ) + v2;
Vector3 P2 = rot * ( B - v2 ) + v2;