Collision detection and welding overview
Havok Physics uses a predictive approach to collision detection, illustrated by the following simplified example of a dynamic sphere colliding with a static landscape consisting of several convex shapes.
First, Havok looks for all nearby bodies which the dynamic body could potentially collide with during this simulation step. To detect potential collision pairs Havok uses axis-aligned bounding box (AABB) per body. This AABB includes body in the current position and body at the end of the frame, with assumption that no collision occurs. AABB is indicated by the red boxes in the following image. When any pair of bodies have their expanded AABBs overlaping, those bodies are considered to potentially collide during this step. This part of collision detection process is called broad-phase:
Next, Havok creates contact points between each pair of bodies which overlap in the broad-phase. To do this, Havok finds the closest points between their shapes within an automatic distance threshold. This process is known as the narrow-phase. The resulting contact distances are positive, which means that the objects aren't touching. The contact constraints are also based on the body's current position, and not its predicted position.
Those contact points define the separating planes between the pairs of bodies. For example, in the image below the sphere cannot pass the separating plane represented as a dashed line.
Note
Havok generates a contact for each primitive shape (cube, capsule, sphere, convex mesh, quad) no matter if the shape is inside a compound or if it’s standalone. In the case of meshes Havok generates the contact for each triangle/quad that the body can breach.
With this approach to collision detection, a body can collide with its predicted separating plane on another body, even if the bodies shouldn't collide. For example, in the following image, a sphere hits the contact plane and bounces
off in the air instead to "fly" over the box:
These collision artifacts are called ghost collisions. Ghost collisions become more noticeable when the distance that a dynamic body moves in a single step increases, so they are dependent on both velocity and step length. There's no universal computationally efficient way to perfectly deal with this problem. That said, Havok Physics combines two different heuristic approaches of modifying predictions to prevent ghost collisions for the majority of cases, in a process known as welding. For example:
The probability of a ghost collision happening is proportional to the number of separating planes that a body can potentially collide against. To reduce the chances of hitting a ghost collision, you can do the following:
- Use welding
- Reduce the delta time
- Reduce the number of triangles representing the shape
- Avoid creating a geometry where many triangles share a single vertex.
- Represent vehicles as convex hulls of the chassis, without wheels. A car collider that “floats” above the ground significantly reduces ghost collision artifacts. For example:
Using the welding in Havok Physics for Unity
Welding does incur a performance cost. For that reason, it is an opt-in feature on a per body level. Havok welds all contacts for a body that is marked for welding, regardless of whether the other bodies in the collision are marked for welding.
To mark any body as welded, you need to designate a welding Custom Physics Body Tag
. This can be assigned to the individual bodies, and identified in the Havok Physics Configuration component.
For more information how to configure Custom Physics Body Tag Names check the Unity Physics package documentation.