Raycast not stopping at a wall?


I’m making a slender game, and I have a raycast to see if the character is visible and take away from health if he is,

but my problem is that the raycast is not stopping at a wall. Here is the coding, I think whatever my error is it is in the function CheckIfVisible. Any help is appreciated! Thanks!


Deleted previous answer, it wasn’t right anyway…

Since this script is known to work, and the issue at hand is that you are not detecting the walls, then, assuming the wall IS BETWEEN the two positions (enemy and player), this should work, so long as your wall has a COLLIDER.

IF your wall ALREADY has a collider, I guess just about the only other possibility is that one of your coordinates (thePlayer.position or theEnemy.position) is not what you expect…

to see for sure, use Debug.DrawLine

add this line at the top of the Update:


and make sure your line is where you expect, and see if it passes through the COLLIDER of the wall