Collision Meshes

From Mod Wiki


Collision meshes are used to improve in-game physics performance. They can also be used to stop players or vehicles catching on small protrusions from meshes, and generally smoothing out player movement over complex shapes.

Collision Meshes for Mapobject Models

When you make a model to be used as a mapobject, by default all the triangles are used as collision parts. This means that bullets, projectiles, players and vehicles collision all have to be calculated against every polygon in the model. Most of the time this is unnecessary (especially for player and vehicle collision) and reduces run-time performance in the game.

Therefore, we can make optimised versions of the mesh, and store them in the same model file with a specific "collision" materials so that the game will only calculate collisions against the optimised versions.

A Simple Example

A small but detailed teapot model.

Here's a teapot model that we want to use in the game. It's not very big, but it has 1600 triangles! At the moment, all the model's triangles will be used to calculate collision, which isn't very efficient or necessary.

We could set "nonsolid" on the teapot's material, but that would mean that players could walk through the object and bullets wouldn't collide with it, which is usually not what you want!

Vehicle and Player Collision

The vehicle and player collision mesh for the teapot, made of 15 polygons.

We usually make really simple shapes that serve as collision models for vehicle and player physics. Most of the time, especially on small objects, the player will not be able to tell they are walking over or around a box or simple cylinder instead of the actual visible mesh.

In fact, in a lot of cases, a simpler vehicle and player collision mesh also makes movement around the world feel smoother, since there aren't any small poking-out pieces to get stuck on.

The vehicle and player collision mesh we've created here is only 18 triangles! It should be fine for the player to walk around without getting stuck, and is much cheaper for collision physics calculations.

For this mesh we use "textures/common/vehicleplayer_clip" to make sure it collides with only vehicles and players (more info at the bottom of this page).

Bullet Collision

The bullet collision mesh for the teapot, made of 160 polygons.

Most of the time, the very simple shape used for player and vehicle collision is not enough to support complex surface interactions like drawing bullet decals onto the mesh. Additionally, a mesh that is simplified for player and vehicle collision might create invisible collision in places where you should be able to shoot bullets through (in this case, the teapot's handle).

Therefore, we need to make a bullet collision mesh. At only 160 polygons, this bullet collision mesh is 10 times less detailed than the visible teapot mesh. This is still keeping enough information about the shape and volume of the teapot to create an accurate representation of how bullets might collide with it.

For this mesh we use "textures/common/rendermodel_clip" to make sure it collides with only bullets (more info at the bottom of this page).

Collision Model Tips

  • You do not have to create separate meshes for the vehicles, players and bullet collision if you don't want to. You can create a single optimised collision mesh and use the "textures/common/collision" material.
  • Unlike shadow hulls, collision meshes do not have to be "watertight", open edges are allowed. However, bear in mind that things in the game will only collide with front-facing polys, so a single flat plane would only have collision on one side of it.
  • Collision meshes are automatically optimised by the game to use polygons rather than triangles. Therefore, co-planar triangles will be optimised down into a single n-sided polygon, for efficiency and performance.
    • As an example, while a simple cube is rendered using 12 three-sided polygons (triangls), the collision optimisation will read it as 6 four-sided polygons (quads).
  • As soon as you add any collision materials to your model file, any non-collision materials will be treated as nonsolid. Therefore, if you only add a player_clip mesh to your model, you will find that vehicles and bullets still pass through.

Valid Collision Materials

The surface type of each material is denoted by the suffix (eg. _metal for metal sound and particle effects). Where no surface type suffix is specified, default effects will be used, which usually look and sound like concrete.

Generic Collision

Vehicles, players, bullets and projectiles will all collide with this material. Nothing passes through.

  • textures/common/collision
  • textures/common/collision_wood
  • textures/common/collision_metal
  • textures/common/collision_concrete

Vehicle & Player Collision

Vehicles and players will collide with this material. Projectiles and bullets will pass through.

  • textures/common/vehicleplayer_clip
  • textures/common/vehicleplayer_clip_metal
  • textures/common/vehicleplayer_clip_wood
  • textures/common/vehicleplayer_clip_concrete
  • textures/common/vehicleplayer_clip_glass
  • textures/common/vehicleplayer_clip_snow

Player Collision

Only players will collide with this material. Vehicles, projectiles and bullets will pass through.

  • textures/common/player_clip
  • textures/common/player_clip_metal
  • textures/common/player_clip_wood
  • textures/common/player_clip_concrete
  • textures/common/player_clip_glass

Vehicle Collision

Only vehicles will collide with this material. Players, projectiles and bullets will pass through.

  • textures/common/vehicle_clip
  • textures/common/vehicle_clip_metal
  • textures/common/vehicle_clip_wood
  • textures/common/vehicle_clip_concrete
  • textures/common/vehicle_clip_snow

"Rendermodel" Collision

Bullets and projectiles (and flyer drones!) will collide with this material. Players and vehicles will pass through.

  • textures/common/rendermodel_clip
  • textures/common/rendermodel_clip_metal
  • textures/common/rendermodel_clip_wood
  • textures/common/rendermodel_clip_concrete
  • textures/common/rendermodel_clip_glass

Special Collision Types

  • textures/common/projectile_clip - Allows bullets to pass through, but not projectiles (eg. rockets and tank shells).