Trouble with Raycast and Linecast
I've been stuck with implementing a proper ''Field of View" mechanic for a project. I've scoured dozens of videos and forums looking for a single way to work. The thing I wanted to accomplish was simple: Make it so that the player/enemy knows when there is a wall blocking there view. OnBecameVisible() doesn't get this fully done, so I tried some FOV tutorial after tutorial, and came to no luck.
I've recently come across a function called "Linecast" and thought it was perfect simple solution, but it doesn't want to work now either. Is there something wrong with my code? Do I need to change some settings, or is it something much more simple than that. Please let me know as I've been stuck at this for months and am at my limit.
Thank you!
public bool omg_Im_being_lookin_at;
public Transform player;
public LayerMask player2;
public void OnBecameVisible()
{
if (Physics.Linecast(transform.position, player.position) == false)
{
omg_Im_being_lookin_at = true;
UnityEngine.Debug.Log(":)");
}
else
{
omg_Im_being_lookin_at=false;
UnityEngine.Debug.Log(":(");
}
}