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?