The complexity of this task increases with the level of detail in the objects' representations: the more intricate the model, the greater the computational cost.
[3] Collision detection frequently involves dynamic objects, adding a temporal dimension to distance calculations.
[4][6] The broad phase aims to answer the question of whether objects might collide, using a conservative but efficient approach to rule out pairs that clearly do not intersect, thus avoiding unnecessary calculations.
In cases where the changes between two frames or time-steps are small and the objects can be approximated well with axis-aligned bounding boxes, the sweep and prune algorithm[5] can be a suitable approach.
Several key observation make the implementation efficient: Two bounding-boxes intersect if, and only if, there is overlap along all three axes; overlap can be determined, for each axis separately, by sorting the intervals for all the boxes; and lastly, between two frames updates are typically small (making sorting algorithms optimized for almost-sorted lists suitable for this application).
As a precomputation, we can take each physical body (represented by a set of triangles) and recursively decompose it into a binary tree, where each node
A quick way to potentially avoid a needless expensive computation is to check if the bounding volume enclosing the two objects intersect.
Axis-Align Bounding Boxes (AABB) and cuboids are popular due to their simplicity and quick intersection tests.
Several algorithms are available for finding the closest points on the surface of two convex polyhedral objects - and determining collision.
These algorithms approach constant time when applied repeatedly to pairs of stationary or slow-moving objects, and every step is initialized from the previous collision check.
[11] The result of all this algorithmic work is that collision detection can be done efficiently for thousands of moving objects in real time on typical personal computers and game consoles.
Where most of the objects involved are fixed, as is typical of video games, a priori methods using precomputation can be used to speed up execution.
When it comes to the exact pairwise collision detection, this is highly trajectory dependent, and one almost has to use a numerical root-finding algorithm to compute the instant of impact.
Using a root finder on these sixty functions produces the exact collision times for the two given triangles and the two given trajectory.
Some iterate the linear interpolation (Newton's method) to calculate the time of collision with a much higher precision than the rest of the simulation.
After an inelastic collision, special states of sliding and resting can occur and, for example, the Open Dynamics Engine uses constraints to simulate them.
At each simulation step, a list of all intersecting bodies is created, and the positions and trajectories of these objects are "fixed" to account for the collision.
In the a priori methods, there is a collision detection algorithm which will be able to predict very precisely the trajectories of the physical bodies.
Moreover, if the discrete step is too large, the collision could go undetected, resulting in an object which passes through another if it is sufficiently fast or small.
However, in all but the simplest cases, the problem of determining ahead of time when two bodies will collide (given some initial data) has no closed form solution—a numerical root finder is usually involved.
Despite this resource limit, and the use of relatively primitive collision detection algorithms, programmers have been able to create believable, if inexact, systems for use in games.
[citation needed] For a long time, video games had a very limited number of objects to treat, and so checking all pairs was not a problem.
In two-dimensional games, in some cases, the hardware was able to efficiently detect and report overlapping pixels between sprites on the screen.
In many cases for video games, approximating the characters by a point is sufficient for the purpose of collision detection with the environment.
In this case, binary space partitioning trees provide a viable, efficient and simple algorithm for checking if a point is embedded in the scenery or not.
Such a data structure can also be used to handle "resting position" situation gracefully when a character is running along the ground.
For instance, if we imagine a high speed racecar video game, from one simulation step to the next, it is conceivable that the cars would advance a substantial distance along the race track.
Big Rigs: Over the Road Racing is an infamous example of a game with a failing or possibly missing collision detection system.
A hitbox is an invisible shape commonly used in video games for real-time collision detection; it is a type of bounding box.
It is common for animated objects to have hitboxes attached to each moving part to ensure accuracy during motion.