- Home /
Quaternion.LookRotation and Plane Direction
I'm attempting to rotate a Plane between two vectors and then detect collisions on that Plane using a Raycast (it's a Plane prefab I added via the editor and includes a BoxCollider). I'm then looking at how far the collision point is from the edge of the plane to determine the percentage the collision point is from the edge of the plane. My planes are dynamic and always perpendicular to the Camera/Raycast origin.
The positioning code looks something like this and works well in most situations. startPos and endPos are both Vector3s.
this.transform.position = (startPos + endPos) * 0.5f;
Vector3 relativePos = startPos - endPos;
Quaternion r = Quaternion.LookRotation(startPos - endPos, Vector3.forward);
this.transform.rotation = r;
Where I'm getting tripped up is that in some cases my plane flips to face away from the camera and the collision point values are the opposite of what I'd expect (higher on the right and lower on the left). This appears to be an issue when the endPos vector is further away from the camera in the Z direction than the startPos. Is there a way to make sure the Plane always faces toward the camera?
Is it the BoxCollider tripping me up here?
Your answer
Follow this Question
Related Questions
Need help getting starting directions within a certain range 0 Answers
Set rotation based on 2 points problem 1 Answer
How to incorporate a rotation towards mouse position in this script? I tried 0 Answers
How can I get the rotated position without using Transform in 2D? 1 Answer
Rotation direction in coroutine 2 Answers