2
votes

I am new to Unity3D and I am pretty sure that something similar was asked before, but apparently I am not googling it right.

I am trying to solve the following problem: I have a car and a road game objects. A player can control the car in a top-down fashion. I want to detect when the car is off the road.

So, I created a mesh collider around the road in order to detect collision in OnCollisionEnter():

enter image description here

Since the RoadBoundry game object does not have a rigid body component, I expect that the car would just pass through it, however it interacts with it in a weird way:

enter image description here

Why the car interacts with mesh that way and how to detect a collision in my case ?

1

1 Answers

2
votes

Check the collider as a trigger

trigger

Then use OnTriggerEnter event.


FYI there is a more simple way, use Physics.Raycast to the ground, and give the path collider a special tag /or special layer.