Hello Im making a game and I raycasts are going through walls.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GrannyEye : MonoBehaviour
{
public GameObject granny;
public float raycastDist;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
RaycastHit hitInfo;
Vector3 fwd = transform.TransformDirection(Vector3.forward);
Debug.DrawRay(transform.position, fwd * raycastDist, Color.red);
if (Physics.Raycast(transform.position, fwd, out hitInfo, raycastDist) && hitInfo.collider.gameObject.tag == "Player")
{
granny.GetComponent<EnemyAIGranny>().seePlayer = true;
}
else
{
granny.GetComponent<EnemyAIGranny>().seePlayer = false;
}
}
}
this is the code for it and when I shoot a raycast its going through objects like cubes and walls and doors, please help me fix that. in every script I write that contains raycasts, the raycasts are just going through objects. the objects have a collider, a mesh renderer, a mesh filter but raycasts are still going through them. please help me