- Home /
 
               Question by 
               italoha · Nov 06, 2019 at 05:07 PM · 
                raycastingfaces  
              
 
              Rotate transform to any touched surface
Can I achieve something like this only with raycasts?
I need to place a quad parallel to a touched face by the user.

 
                 
                untitled-1.jpg 
                (111.7 kB) 
               
 
              
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by BastianUrbach · Nov 06, 2019 at 09:56 PM
Physics.Raycast can output a RaycastHit, which has a normal field that contains the direction of the surface that was hit (as a vector perpendicular to it). You can then use Quaternion.LookRotation to determine the rotation of the quad. 
 Kinda like this: 
RaycastHit hit;
if (Physics.Raycast(ray, out hit)) {
    quad.position = hit.point;
    quad.rotation = Quaternion.LookRotation(hit.normal, Vector3.up);
}
 
               Depending on which way your quad is facing, you might need to flip the normal vector.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                