- Home /
 
               Question by 
               solocs · Aug 12, 2021 at 08:54 PM · 
                raycastlayermasktexturecoord  
              
 
              Why do RaycastHit.textureCoord values only appear properly when a layer mask is used?
 //The textureCoords only output properly if a layermask is included in the //Raycast for some odd reason.
     
 var isHit = Physics.Raycast(ray, out var hit, 10.0f);
     
 if (isHit)
 {
             //raycastsgive you a texture coordinate
            Debug.Log("Texture coordinates: " + hit.textureCoord.x + "," + hit.textureCoord.y); 
 }
Quad is using "Default Layer"  
 
 The result: https://i.imgur.com/0TXy2sf.gif
 Now I add a layer mask:
 //the textureCoords only output properly if a layermask is included in the Raycast for some odd reason
 var isHit = Physics.Raycast(ray, out var hit, 10.0f, LayerMask.GetMask("HitLayer")); 
     
 if (isHit)
 {
            Debug.Log("Texture coordinates: " + hit.textureCoord.x + "," + hit.textureCoord.y);
 }
Quad now uses "HitLayer" 
 The result: https://i.imgur.com/avDH3n6.gif 
 Can anyone explain why this happens????
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                