- Home /
 
RaycastHit.normal Problem
Hi,
I'm having a problem with RaycastHit.normal. I have the code below:
private var tGraphic : Transform; //O Objeto que conter o grfico que exibir a seleo; var graphicOffset : Vector3; //Deslocamento referente largura do objeto tGraphic
 
                function Start(){
     tGraphic = GameObject.Find("Graphics").transform;
 }
 function FixedUpdate () {
     var hit:RaycastHit;
     var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     if(Physics.Raycast(ray, hit, 1000)){
         print(hit.normal);
         if(hit.transform.gameObject.name == "Ground"){
             var gridPosition = hit.point;
             gridPosition.x = Mathf.Ceil(gridPosition.x);
             gridPosition.z = Mathf.Ceil(gridPosition.z)-1;
             tGraphic.transform.position = gridPosition + graphicOffset;
             Debug.DrawLine(ray.origin, hit.point);
         }
     }
 }
  
               I have a cube and I point the mouse to the cube's upper face, it returns the normal (0.0, 1.0, 0.0).
After this, I point to the front face, it return the normal (0.0, 0.0, 1.0)
Then, when I point to the upper face again, it still returning (0.0, 0.0, 1.0)
Please, can someone help me with this problem that seems to be simple?
Answer by Owen-Reynolds · May 07, 2011 at 05:58 PM
I'm guessing it works fine and your Print is just giving confusing results.
For a different test, try: Public var N : Vector3; in global, use N=hit.normal; in your IF and take a look in the Inspector as you move around.
That is it!! Thanks a lot, the Print doesn't working like I expected, but in the inspector the results are working.
Your answer
 
             Follow this Question
Related Questions
RaycastHit.normal problem 0 Answers
default cylinder to indicate hit.normal 1 Answer
Raycast Not Drawing In Target Direction 0 Answers
Raycast from NPC 0 Answers