Intermediate Tutorial


MeshCollider for Terrain Geometry


30 minutes

Posted on: January 10, 2018

Learn Sumerian
MeshCollider for Terrain Geometry

Tags

mesh
collider
terrain
geometry
physics

In this tutorial you will learn about:

creating a mesh collider

For performance, and by default, we often use other primitive shape colliders, such as Sphere, Box, and Cylinder to approximate the shape of a collision mesh. In this tutorial, we create a MeshCollider for a terrain geometry. When you want to use a mesh as a terrain geometry, your Rigid Body component will be on the entities that collide with the mesh.

Note: At the time of this writing, the Collider component’s Shape options don’t include the MeshCollider collider type. Therefore, the only way to create a MeshCollider shape is by using code in a Script component.

This is the scene we will build in this tutorial. For best results, be sure you are using the latest version of your browser.

Prerequisites

Before you begin, complete the following tasks and tutorials:

Step 1: Add Terrain

  1. Create a new scene using the Default Lighting scene template.

  2. Drag the mesh terrain object, mountain.fbx, which you already downloaded (see Prerequisites) onto the canvas to upload it to your scene.

  3. Navigate to the Assets panel, and then drag the mountain entity onto the canvas.

You now see the mountain entity, which is the terrain, in your scene.

Note: You might want to reduce the Intensity of the Directional lights. You can access these lights in your Default Lights parent entity.

Step 2: Add a MeshCollider

This step to add a MeshCollider follows a process similar to the one in the MeshCollider Torus tutorial.

  1. Expand the parent mountain entity until you can see its child pPlane1_lambert1 entity.

    We want to add a MeshCollider onto this entity because this entity carries the Geometry component.