Home » Games

How-to: Build Accurate Collision in Nifs

Ranked #4,041 in Games, #172,440 overall

A medium length tutorial on making you own accurate collision for Oblivion and other NetImmerse based games such as Morrowind, Civilization 4 etc.

By the time you're done this tutorial you will know everything that you need to know to make accurate collision meshes for Oblivion. Of course there is more to know but you really don't need to know more than that; if you're interested after this I have other tutorials (coming soon :)) giving more information about mesh editing.

Requirements / Getting Started

Requirements

If the object is a static:
- Gmax (super easy and free) OR Blender (slightly harder, free and open source) OR 3dsMax (expensive, haven't ever used it so don't know its ease of use)
- Niftools Max (for Gmax or 3dsmax) and/or Blender plugin
- A 3d mesh (here after refered to as a model)
- A game that will load the finished object in Nif format. Great ones include The Elder Scrolls IV Oblivion and The Elder Scrolls III Morrowind (you'll need a PC version rather than a console to be able to use user generated content).
- PYFFIis required by the blender nif exporter/importer, and useful for other mesh projects.

If the object is any thing but static (such as clutter, weapon, armor etc.):
- Blender (and for less skilled model creators Gmax as well is helpful)
- a model
- Niftools Blender plugin
- PYFFIis required by the blender nif exporter/importer, and useful for other mesh projects.
- A game that will load the finished object in Nif format. Great ones include The Elder Scrolls IV Oblivion and The Elder Scrolls III Morrowind (you'll need a PC version rather than a console to be able to use user generated content).

Getting ready
- install your game (must be PC version)
- install modelling program(s)
- install PYFFI
- install Niftools plugins
- create a mesh (or use one you already have what ever), save in an importable format (for Gmax: nif, gmax, 3ds, prj, shp, dxf ; for Blender: nif, blend, obj, 3ds, lots of others). If in modelling program's native format just open it otherwise you will need to import mesh to modelling program. Those instructions are based on importing a nif, so will be similar but slightly different for other formats.

Some options for the requirements and model creation

Loading

Creating the Collision

Gmax

Now for the actual creation of the collision! Here are the instructions for using Gmax (or 3ds Max which is similar). Remember that Gmax only supports static so if it is a weapon or clutter you'll have to use something else (such as Blender, see below).

Select the mesh that you want to add collision to (by left clicking it), then click edit --> clone --> name whatever you want - not important. Then go into modify mode (see pic) --> modifier list (see pic) --> select bhkRigidBody (way down near the bottom):Setting up collision with Gmax

Then you may want to change some settings:
There are two settings that are a good idea to change here; type of collision and material. For material just select the closest match to what type of object it is. For the collision you just click the radio button beside the type you want:
Gmax collision settings

The types of collision available in gmax:
  • No collision; just no collision; don't select this.
  • Axis Aligned Box: the collision is just a box as big as the largest dimensions of the mesh, good for cubes and simple objects that just need to collide like walls. The box is aligned with the game axes so may not be the smallest possible - if doing a box I would reccomend an oriented box instead.
  • Sphere: same thing except it is a sphere not a box; good for things like globes.
  • Cylinder: again just another basic shape that can fit approximately around the mesh
  • Convex Shape: the best for most models; it is almost the same as the real model. However such things as arrows usually bounce of it instead of "puncturing" and sticking in. Hence it is best used for miscellaneous objects and clothing/armour ground models.
  • Strip shape & packed strip shape: the most exact of all collision forms however if the mesh is not highly optimized it will cause massive slowdowns. Best used on things like fences, doors etc. Best to make a mesh that is a composite of squares with slight editing to fit the basic shape of the object (like a just three rectangles to fit a highly decorated arch) to minimize slowdown and still get most of the benefits. The game engine does the exact same thing with these two shapes and they have really no speed difference so it doesn't matter which of the two you choose if you choose a strip shape.


Then you have to go into Utilities ---> more ---> double-click NifProps. Then check the button before "Is Collision Mesh" and under Rigid Body select the same material as you selected previously in the other settings.

Now you just have to export the file as a .nif and you have a working static object with collision.

If you selected Strips Shape or Packed Strips Shape you should first optimize your cloned mesh to reduce game slowdown. To optimize do one of these two methods in Gmax before puting in the bhkRigidBody modifier:
A) Instead of your clone you can make a roughly matching model that is a fair bit rougher and has a much lower vertex and face count.
B) select your clone and then go Modifiers --> Mesh Editing --> Optimize. This will bring up a settings box on the right hand side of the screen again and in it you want to set both the face thresh and edge thresh up significantly (don't worry that it looks horribly rough this is not being seen it is just collision now). I usually set them to something between 20 and 30 depending on the model. Then right click your model and select convert to... Editable Mesh and then go back to adding collision to that.

Notes:
  • Morrowind ONLY accepts Strips Shape.
  • Oblivion accepts all of those types of collision shapes
  • Despite the options existing in Gmax to select non-static collision it will only export static collision.

Blender

Here are instructions for doing the same thing with blender (or making non-static collisions).

First import model (or open it). Then EITHER:
A) If it is a multiple mesh model select only 1 part (by right clicking on the partt). Then press shift-D and right away single left click with your mouse, without moving it at all. Now you have a mesh that is in the same position as the original, you are turning this duplicate into the collision.

B) make an optimized version of the mesh to serve as the collision instead of duplicate - highly reccomended if you are using convex hull or Triangle shape collision. There are two ways of doing so: from scratch make a mesh that roughly conforms to the shape or duplicate the mesh and optimize. Unfortunately I don't know how to do optimize a mesh in Blender so for me what I do is optimize the mesh in Gmax (see above for instructions) and then export it and import that mesh after importing the main mesh. Doing that then just select the optimized mesh and follow the instructions substiting this mesh for the duplicate mesh.

To turn this mesh into the collision make sure you only have it selected by pressing A once or twice until there are no pink lines visible then right click the mesh you want (doesn't matter whether it is the duplicate or not since they are identical). Then go into object mode, press F7 (object) and select bounds and wire.
Photobucket
Now go into logic by pressing F4, there select bounds and then you have a new box saying "Box"; click it and select the type of collision you want.
Photobucket
The types of collision:
  • Box: the collision is just a box as big as the largest dimensions of the mesh, good for cubes and simple objects that just need to collide like walls.
  • Sphere: same thing except it is a sphere not a box; good for things like globes.
  • Cylinder: again just another basic shape that can fit approximately around the mesh.
  • Cone: and another basic shape!
  • Convex Hull: the best for most models; it is almost exactly the same as the real model. However such things as arrows usually bounce of it instead of "puncturing" and sticking in. Hence it is best used for miscellaneous objects and clothing/armour ground models.
  • Triangle Mesh: the most exact of all collision forms however if the mesh is not highly optimized it will cause massive slowdowns. Best used on things like fences, doors etc. Best to make a mesh that is a composite of squares with slight editing to fit the basic shape of the object (like a just three rectangles to fit a highly decorated arch) to minimize slowdown and still get most of the benefits.

Now you just have to repeat those steps for each seperate mesh part that you want to have collision. Often for multipart models you do not need to put in collision on all sections - so don't it just will use unneccesary system resources in game - like on a head you don't need collision on the eyes or the ears; nothing is likely to colide with them and if it does it won't be noticeable. Once you're done making all the collision meshes you need to export the file as a nif.

A usually cheap source for one great game that uses nif files

Loading

Got any questions, suggestion et al?

Post them here

I am always happy to hear questions, suggestions etc. and I will do my best to give detailed answers to any questions.

If this (or one of my other tutorials) has helped you and you have some to spare why don't you:









  • Cecil101 Feb 12, 2012 @ 10:32 am | delete
    The convex hull seems to be more resource intensive than the triangle mesh collision. The descriptions can be confused but if the mesh is simplified, triangle mesh is the way to go

by

PacificMorrowind

I go by Pacific Morrowind in the Elder Scrolls Modding community and have a few mods done be me. I have also contributed to some large and medium scale... more »

Feeling creative? Create a Lens!