Skip navigation

I posted the following on the Card Kingdom development blog.

Two features of Havok Physics that we will be using for this game are the character controller and phantom collisions. The character controller is used, as the name suggests, to control a physical body as user controlled object. It handles the various states a character can be in: on the group, wanting to jump, in the air, climbing a ladder, flying, etc. It also supports custom states as well, so crouching, swimming, any state that the physical representation of the body needs act differently in, it handles.

The options for the character controller and each state are staggering and give fine grained control over how the character moves and interacts with the world. The character controller itself can have options for mass, friction, the maximum slope it can stand on before sliding down and shape of collision. For the “on the ground” state, options for clamping the maximum downward velocity to gravity, setting the character’s movement speed while moving on an incline plane to act as if it were on a flat plane, maximum acceleration, and even movement speed can be set. For “in the air”, the air movement speed can be set differently than the “on the ground” movement speed to give varying levels of control to the character while in air. The “jumping” state is probably the most useful and headache-solving state in the entire system: there is a parameter for setting the jump height. That’s right, you set the jump height of the character and it will jump that high pretty much always. There are some cases when the rigid body that is controlling the character is either penetrating the ground or is slightly above the ground and the jump is not exactly correct, but 9 times out of 10 the character jumps to the height specified. There are other states that Havok has built-in support for, such as climbing and flying, but we will not be using those in our game.

Phantom collisions are, again, as the name suggests, collision volumes that send collision information to the physics system, but have no physical presence in the world. They act as trigger volumes in the world and track which objects enter and leave their area. This makes phantoms ideal for setting zones in the world, or starting an event when the player enters an area. For our purposes, we are using phantom collisions for our hit detection. We can listen for when a particular object enters the volume and when it leaves and it only get’s added once, meaning that multiple calls to “take damage,” for example, will not happen. The phantoms can also be “attached” to other objects in the world by setting its transform.

As you can see from the images above, on the left is our game, on the right is the Havok Physics Visual Debugger (which I gush over in a previous post, and rightfully so). The first image shows the character, which is controlled by the character controller, holding a weapon with a phantom collision on it. The phantom is attached to the weapon, which is intern attached to the player. Any movement the player makes, the weapon, and phantom, also make. In the second image, the character is swinging his sword and the phantom is following. A discerning eye will also notice that some of the boxes are starting to float. This is our initial indication that the box has entered the phantom’s collision zone.

The next step for phantom collision is to filter the objects that can be added to the phantom’s internal list, so objects like the floor, the player, other weapons, etc. don’t get processed. After that, enabling and disabling the phantom collision is needed so a character in a non-attacking state does not send “take damage” messages to objects that it happens to glace by. The next steps for the character controller is just tweaking and fine tuning until it feels right for the player.