I’m trying to make my walls turn transparent when they are between my player and the camera, and I’m using Raycast to detect when this happens. My current issue is the wall to the left of my player (even with considerable space between the two) is being hit by the Raycast. It was working fine before, but I can’t seem to figure out why my Raycast seems to be grabbing to the wall to the left. Any ideas what I’m overlooking?
I’ve drawn 3 lines: What my camera is aiming the Raycast at, what is actually being hit, and my camera’s forward.
void LateUpdate()
{
RaycastHit hit;
Ray ray = GetComponent<Camera>().ScreenPointToRay(thePlayer.transform.position);
if (Physics.Raycast(ray, out hit))
{
Debug.DrawLine(Camera.main.transform.position, thePlayer.transform.position, Color.blue);
Debug.DrawLine(Camera.main.transform.position, hit.transform.position, Color.red);
Debug.DrawRay(Camera.main.transform.position, transform.forward, Color.green);
Transform objectHit = hit.transform;