When got the vector by hit.normal by click,normal is abnormal in the typical case.
I placed the default Quad at (0,0,0),And attach the code to Empty Object created :
void Update()
{
if (Input.GetMouseButtonDown(0)) {
Ray ray = new Ray();
RaycastHit hit = new RaycastHit();
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
//Ray from camera to clicked point on the screen
if (Physics.Raycast(ray.origin, ray.direction, out hit, Mathf.Infinity)) {
Debug.Log("hit.normal.x=" + hit.normal.x.ToString("e"));
Debug.Log("hit.normal.y=" + hit.normal.y.ToString("e"));
Debug.Log("hit.normal.z=" + hit.normal.z.ToString("e"));
}
}
}
Log :
hit.normal.x=0.000000e+000
UnityEngine.Debug:Log(Object)
HitNormalTest:Update() (at
Assets/HitNormalTest.cs:23)
hit.normal.y=6.123234e-017
UnityEngine.Debug:Log(Object)
HitNormalTest:Update() (at
Assets/HitNormalTest.cs:24)
hit.normal.z=-1.000000e+000
UnityEngine.Debug:Log(Object)
HitNormalTest:Update() (at
Assets/HitNormalTest.cs:25)
Why is not the Y Zero?
Is there the way to get correct normal?