Unity: detect if path is clear using Raycast
0 Votes
1144 Views
Currently my code looks like this:
Vector3 tempPos = transform.position;
Vector3 checkPos = new Vector3(tempPos.x, tempPos.y, Mathf.Round(tempPos.z + 1));
if (Input.GetKey(KeyCode.W))
{
Vector3 direction = checkPos - transform.position;
Ray ray = new Ray(transform.position, direction);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
Debug.Log(hit.point);
}
Debug.DrawRay(transform.position, direction, Color.black, 20, false);
}
however even when i am right up against an object, I get nothing from my Debug.Log() statement. As a matter of fact, I cannot even call a Debug.DrawRay() statement as it doesn’t show anything either. What on Earth could I be doing wrong? Any help would be appreciated. Thanks in advance!
1
Answers