Search code examples
unity-game-enginemapboxcollider

How to prevent the car from getting out of the way in a Unity3D driving simulation that uses MapBox maps?


I'm trying to make a car simulation that uses real world map. I'm currently using Mapbox for getting map features. For car asset I'm using Unity's Standart Asset.

My question is how can prevent the car from get off the road. There are many another features like park, lake, etc,.. And I want to make the driver use only the roads for driving.

Is there anything I can do? I thought about add collider for all other features(park, garden, ..) but there are good amount of features for adding collider. Is there any other solution?


Solution

  • If you get the road information in terms of coordinates from Mapbox (which I don't know) you could write a script wich would automatically create a mesh with mesh collider on each side of the road.

    You can also create a collision mesh in a software like Blender, Maya, 3DSMAX or other and import it to Unity3D. You could then use this imported model with the mesh collider.

    Here you can see one of many tutorials on Creating Custom Collision for your Unity Scenes.