- Home /
 
using a textured plane as a cursor, problem successfully rotating relative to RayHit.normal
I am using a raycast from the camera's perspective to move a plane with my pointer texture to the rayhit.position. this works well as long as the surface is facing the default rotation of the plane. so i have tried a lot of trial and error to get the plane rotated to appear correct. first i set the rotation to that of the collider, but Quaternion.LookRotation() seemed to get me the closest. The problem is that it just doesn't face the proper direction no matter what I try. I have tried setting the up direction in LookRotation to forward, down, and I'm pretty sure every other direction but I just can't seem to get it working. Am I doing it wrong?
 surfaceCursor.transform.rotation = Quaternion.LookRotation(cursorRayHit.collider.transform.TransformDirection(Vector3.forward), cursorRayHit.normal);
 surfaceCursor.transform.position = cursorRayHit.point + cursorRayHit.normal*offset;
 surfaceCursor.SetActive(true);
 
 
              ok, so more specifically, the problem that i'm having is that it displays fine on almost every surface except for the left and right sides (i think) of the object I am pointing at, in this case i'm testing on a cube.when you point at those sides, the plane goes 90 degrees and appears to be sticking out of the cube. So is it translating wrong? Or are the normals pointing in the wrong direction somehow?
I realize now that as I move the cursor around, in some positions the forward and the up (the surface normal) directions from LookRotation() are pointing in the same direction and that is when the problem occurs. do I write special code to hande the forward and reverse side normals? and if so, how can I tell when the normal is facing in the forward or reverse side direction?
Your answer
 
             Follow this Question
Related Questions
Using Raycast Normal to match surface rotation to instantiated gameobject? EXAMPLE GIF Included 0 Answers
Raycast not applying force to point 1 Answer
How do I measure how far from the normal a raycast is when hitting a surface? 0 Answers
RaycastHit.normal returns NaN 0 Answers
problem with multiple raycasting from multiple gameobjects 0 Answers