Hey everybody, Lately I’ve been using Unity a lot for school related purposes, and I’m now the lead programmer for our final game project which we’re doing in Unity. With that in mind, I figure it would be a good idea to join this forum and get friendly with you all :P.
Anyway, My first question, is how do I create a quaternion rotation that represents the rotation between 2 points? I don’t know if that’s the proper way to word the question, so I’ll explain what I’m trying to do.
I have 2 points in 2D space, that is, the X value is always the same, and the Y and Z values change depending on their location on a plane.
I’ve also got a 3D plane that I want to stretch between the 2 points, so I need to rotate the plane around the YZ axis to the angle between my 2 points. This would be fine If Unity worked in Euler angles, but Unity refuses to conform to my primitive ways and demands I learn to use quaternions.
Here’s what I’ve got so far, this code refuses to offer any relevant results:
var rotangle = Vector3.Angle(
Vector3(projectedPoints[1].y,projectedPoints[1].z, 0),
Vector3(projectedPoints[2].y,projectedPoints[2].z, 0)
);
//Set the plane position between the 2 points
currentplane.transform.position =((projectedPoints[1] + projectedPoints[2])/2);
currentplane.transform.rotation = Quaternion.AngleAxis(rotangle, Vector3.right );
I can’t for the life of me figure out what I’m doing wrong :(.
EDIT: It appears the rotation between the 2 points is incorrect, But I still can’t figure out how to get the correct rotation.