Collisions and Navmesh
Last updated
Last updated
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.
Make sure that Enable Collisions or Enable Navmesh is ticked:
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.
Let's consider a voxel world with the following LODs:
If Compute Visible Chunks Collisions is on and Visible Chunks Collisions Max LOD is 5, collisions will be computed on the following chunks:
If Compute Visible Chunks Navmesh is on and Visible Chunks Navmesh Max LOD is 0, navmesh will be computed on the following chunks:
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.
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:
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:
You will see this kind of debug view:
Note how the collision meshes (in blue) are much higher res than the displayed meshes (in white):
Using a Voxel LOD Volume can also be useful to enable collision/navmesh in a specific area.
You need to enable runtime generation of navmesh in your Project Settings:
You need a Nav Mesh Bounds Volume:
You can choose the Collision Presets you want to apply to your voxel world:
Unreal has two kind of collisions: complex and simple.
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:
Complex collisions can be viewed by setting the view mode to Visibility Collision:
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:
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:
Simple collisions can be viewed by setting the view mode to Player Collision:
Notice how low res they are compared to the complex collisions:
This is using Num Convex Hulls Per Axis = 2.
Using Num Convex Hulls Per Axis = 4:
If you are using simple collisions, you can enable Simulate Physics:
And do fun stuff like this:
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.