The player uses a raycast to check if he is looking at a door (a door with a collider on it (mesh collider if that makes any difference)). When he clicks on it, the door opens. when he clicks on it again, the door will close. But behind the door, there is a seat that moves the player to it when clicked on. Here is the problem: when I click on the door, the raycast seems to pass through the door and hit the seat. Is there any way this can be fixed so that the raycast stops at the door?
Here is the question: how close is the chair to the door? If on the other side of the room, consider defining maxDistance
(Raycast documentation). Play with the value and see if it fits. Or, if it is very close, use LayerMask (though creating new Layer just for chair…)
Is there any reason for the collider to even be there when you’re not supposed to get into the car? One solution would simply be disabling the seat-collider when the car door is closed. I don’t think it’s really elegant though, even if it solves the issue. An image of your setup would be nice. There’s probably somewhere the colliders overlap or you have a gap.
I fixed it! Instead of having multiple raycasts that each looked for one layer, (ignoring any other layer) I used one layermask and had each function check if the hit.collider.transform.tag is equal to, say, “seat” and if so, handle the seat logic.