My RayCast practicce scripts will be below
RaycastHit hitinfo;
transform.Translate(transform.TransformDirection(Input.GetAxis(“Horizontal”),0,Input.GetAxis(“Vertical”)));
Debug.DrawRay(shoot.transform.position,shoot.transform.TransformDirection(-Vector3.right)*10,Color.red);
bool collide = Physics.Raycast(shoot.transform.position,shoot.transform.TransformDirection(-Vector3.right)*10,out hitinfo,20f);
if(collide)
{
Debug.Log(“hit something”);
}
else
{
Debug.Log(“hit nothing”);
}
}
In play mode, as first beginning, the ray coming from the shoot hit a Cube, and console Debug.Log–>Hit Something
But when I move the shooter the place, and move back , targeting the Cube, console no longer Debug.Log
–>Hit Something. It always say “Hit Nothing”
That’s very weird, at first it does work, but when move back it doesn’t work anymore