Hello!
I’ve been trying to make my camera not move through walls with RaycastHit, but I really can’t get it to work. This is what I’ve come up with so far.
void Update ()
{
RaycastHit wallHit = new RaycastHit ();
Ray wallRay = new Ray (car.transform.position, camera.transform.position);
if (Physics.Raycast (wallRay, out wallHit, distance)) {
if (wallHit.collider.tag == "Wall") {
camera.transform.position = wallHit.point;
}
}
}
Can you spot what I am doing wrong? Any help is massively appreciated!