Question by 
               Quentin-S · May 16, 2017 at 01:14 PM · 
                raycastraycastingtilting  
              
 
              Raycast not working with tilted plane
Hello !
Here's my configuration : 
I'm am trying to evaluate the angle of the plane under the cube. It works when :
- Both the cube and the plane are horizontally placed 
- The plane is horizontal and the cube is tilted 
But not and here's my problem when :
- -The cube is horizontal and the plane tilted 
I don't understand why the raycasts hit show the same value whereas the plane is titled
Here's the code :
 public class Raycast : MonoBehaviour
 {
 
     float d1, d2, D;
     double alpha, beta;
     void FixedUpdate()
     {
         RaycastHit hit;
         Vector3 p1 = new Vector3(2.0f, 0, 0);
         Vector3 p2 = new Vector3(-2.0f, 0, 0);
        
 
         if (Physics.Raycast(p1, Vector3.up, out hit))
         {
             Debug.DrawRay(new Vector3(2.0f, 0, 0), Vector3.up, Color.green);
             print("Found an object from p1- distance: " + hit.distance);
             d1 = hit.distance;
         }
 
         if (Physics.Raycast(p2, Vector3.up, out hit))
         {
             Debug.DrawRay(new Vector3(-2.0f, 0,0), Vector3.up, Color.red);
             print("Found an object from p2 - distance: " + hit.distance);
             d2 = hit.distance;
         }
 
 
         D = Math.Abs(d2 - d1);
 
         Debug.Log("D : " + D);
         if (D != 0)
         {
             alpha = (Math.Atan(4 / D))* 180 / Math.PI; //conversion en degrés
 
             Debug.Log("alpha : " + alpha);
 
             beta = (90 - alpha);
 
             Debug.Log("TILT ANGLE : " + beta);
         }
         else
         {
             beta = 0;
             Debug.Log("beta : " + beta);
         }
     }
 }
Thanks for your help
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Raycast not working on tilted plane 0 Answers
I'm Trying to get a 3D Model to follow a Raycast 0 Answers
I can't get RayCast to report the collider I want. 1 Answer
Blink, Dash, Raycasting 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                