Continuous Collision Detection (CCD) |
This section shows how to use Continuous Collision Detection.
Tip |
---|
More general information about CCD can be found in the following article: Continuous Collision Detection (Background Information) |
This topic contains the following sections:
The normal Discrete Collision Detection checks for collisions at the current objects positions. Then the game moves the objects to new positions and in the next frame the collision detection checks for collision at the new positions.
Here is an example (from the ContinuousCollisionDetectionSample). The capsule is moving from top to bottom. The table is moving from left to right.
In the first frame of the game the objects are at their top and left positions. In the next frame of the game the objects are at their bottom and right positions. Discrete Collision Detection does not detect a collision because only the start and end positions were checked.
This problem is known as "tunneling" and happens for small and fast moving objects in a game. A game must make sure that tunneling does not happen for game critical objects, for example, for bullet that is shot at an enemy or a rocket that should hit a wall.
Continuous Collision Detection (CCD) provides methods to compute the first time of impact of objects that are in motion. With CCD the intermediate collision can be found: (Objects in red show the first time of impact.)
To compute the first time of impact the CollisionDetection class has the method CollisionDetectionGetTimeOfImpact(CollisionObject, Pose, CollisionObject, Pose, Single). This method takes two objects (positioned at their start poses) and the target poses as parameters. It returns the timeOfImpact, a value in the range [0,1]:
Return Value | Description |
---|---|
timeOfImpact = 0 | The objects touch at the start poses. |
timeOfImpact = 1 | The objects either collide at the end poses or they do not collide at all. |
0 < timeOfImpact < 1 | The objects collide somewhere between start and end pose. The returned value indicates the time when the objects collide. |
The last parameter of CollisionDetectionGetTimeOfImpact(CollisionObject, Pose, CollisionObject, Pose, Single) is the allowedPenetration. This parameter should be set to a small positive value. For example, when most game objects have an extent around 1 unit (1 m) an allowedPenetration of 0.01 (1 cm) is a good choice. If the parameter is 0, the time of impact is the exact time when the objects start to touch. But because of numerical inaccuracies or approximations in the CCD-phase the discrete collision detection may or may not detect a collision at this time. Therefore, it is recommended to allow penetrations in the CCD computation. This way, when the objects are moved to the time of impact the collision detection will find a solid contact.
DigitalRune Geometry supports two CCD modes that can be set with CollisionDetectionContinuousCollisionDetectionMode:
CCD Mode | Description |
---|---|
Linear | The continuous collision detection considers only the linear movement of the objects involved. The rotational movement is ignored. This mode is faster, but less accurate. |
Full | The continuous collision detection considers the linear and the rotational movement of the objects involved. This mode is slower, but more accurate. |