Collisions and Navmesh

From Voxel Plugin Documentation
Jump to navigation Jump to search

Collisions and navmesh are regrouped into a single page as their settings are very similar.

As voxel worlds are usually huge, it's not possible to enable high quality navmesh & collisions on the entire world.

Instead, the plugin tries to enable navmesh & collisions only where needed. This is mainly done by enabling them near Voxel Invoker Components, and on visible chunks that need to be processed anyways for rendering.

Note

Note that you also still need to add a NavigationInvoker to the pawn.

Free and Pro

This feature is available in both Free and Pro. Some of the tutorials might not entirely apply to Free.

Enabling Collisions/Navmesh

Make sure that Enable Collisions or Enable Navmesh is ticked:

kdLL9Pp.png

lylEQiV.png

Enabling on visible chunks

Collisions & navmesh can be enabled on the visible voxel chunks. This is relatively cheap as the chunks are already processed.

However, if the chunks have a high LOD, the collisions/navmesh will not match the true geometry and might lead to unwanted behavior.

To enable collisions/navmesh on visible chunks, tick the corresponding option. You can choose the maximum LOD that can be used for them.

pRbAAOM.png

O8Q7rgc.png

Let's consider a voxel world with the following LODs:

5oll0SF.png

If Compute Visible Chunks Collisions is on and Visible Chunks Collisions Max LOD is 5, collisions will be computed on the following chunks:

Y4h0VCm.png

If Compute Visible Chunks Navmesh is on and Visible Chunks Navmesh Max LOD is 0, navmesh will be computed on the following chunks:

OBl2uaW.png

You usually want to leave Visible Chunks Navmesh Max LOD to 0, as an unprecise navmesh can lead to unwanted behavior.

On the other hand, it's fine to leave Visible Chunks Collisions Max LOD to something higher, as it's always better to have low res collisions than no collisions at all.

Enabling near a voxel invoker

A voxel invoker can also trigger collisions/navmesh near it. See World Size and Level of Details for more details on invoker components.

If you use voxel invokers to add collisions/navmesh, you should disable the Visible Chunks options.

On your voxel invoker, tick Use for Collisions/Use for Navmesh and set the wanted range in cm:

fhen2Ia.png

The plugin will create high resolution chunks up to that range.

These chunks will have no impact on the rendering: if close enough to be rendered at LOD 0, they will be the same as the rendered ones; if not, they will be hidden LOD 0 chunks.

You can see them using voxel.renderer.ShowCollisionAndNavmeshDebug 1.

For instance, with Visible Chunks options disabled and the following settings:

cAePoYL.png

You will see this kind of debug view:

s5uzXA0.png

Note how the collision meshes (in blue) are much higher res than the displayed meshes (in white):

mDXCMO2.png

Using a Voxel LOD Volume can also be useful to enable collision/navmesh in a specific area.

Setting up Navmesh

You need to enable runtime generation of navmesh in your Project Settings:

3Zhu2gJ.png

You need a Nav Mesh Bounds Volume:

kabxmx3.png

Setting up Collisions

You can choose the Collision Presets you want to apply to your voxel world:

0X2UKCX.png

Unreal has two kind of collisions: complex and simple.

Complex Collisions

Complex Collisions are used for static objects that do not need to have their physics simulated. They do not have to be convex, so they are a perfect fit for voxel worlds.

Using them on voxel world will generate perfectly matching collision shapes.

Usually you want to use them: just leave Collisions Trace Flag to Use Complex as Simple:

DllQ1zd.png

Complex collisions can be viewed by setting the view mode to Visibility Collision:

x4YQKCb.png

YvtgvB0.png

Simple Collisions

Simple Collisions, on the other hand, are needed if you want to simulate physics on your entire world (eg, bounce a voxel world on another).

To use simple collisions, either set Collisions Trace Flag to Simple And Complex or Use Simple as Complex:

WVg4PIC.png

Simple collisions need to be convex: as such, they will not exactly match the voxel geometry.

Decomposing a mesh into convex hulls is a very complex & expensive problem. To go around that, the plugin simply split the voxel chunks into subchunks, and uses one convex hull for each.

The number of subdivision to apply can be configured using Num Convex Hulls Per Axis:

D7qYpcd.png

Simple collisions can be viewed by setting the view mode to Player Collision:

FLYd9lP.png

Notice how low res they are compared to the complex collisions:

30pka01.png

This is using Num Convex Hulls Per Axis = 2.

Using Num Convex Hulls Per Axis = 4:

rsAHVqM.png

Enabling Physics

If you are using simple collisions, you can enable Simulate Physics:

vCdXG1b.png

And do fun stuff like this:

Preventing actors from falling through the world

If an actor goes on a part of the voxel world without collisions, it will fall.

To prevent that, you can use a Voxel Physics Relevancy Component: this component will disable physics when needed, and enable them back when possible.

Alternatively, you can setup your own logic by calling AreCollisionsEnabled in your blueprint.