Collision detection: do two objects touch?
Collision detection asks whether two shapes touch or overlap. A game can use the answer to award a coin, stop movement, or lose a life. Detecting contact and deciding what happens afterward are separate jobs.
Compare two number-line segments
Here the shapes are simple segments on one horizontal line:
# language: en
let firstLeft = 10
let firstRight = 30
let secondLeft = 25
let secondRight = 40
say firstLeft <= secondRight and secondLeft <= firstRight
The output is true. The segments share positions from 25 through 30. With these comparisons, touching at an endpoint also counts. Each segment must have its left endpoint at or before its right endpoint.
A two-dimensional rectangle test needs to check both horizontal and vertical ranges. A three-dimensional test has another direction to consider.
The shape used for contact
A hitbox is a simple shape chosen to represent an object for collision checks. It may differ from the visible picture. That can make checks easier, but a large hitbox may feel unfair to a player.
Pliro’s touching3D tests contact between supported 3D objects. It does not automatically move them apart or act as a 2D sprite collision function. Read its reference for the actual geometry rules.
Try setting secondLeft to 31 in the example. Predict why the answer changes.
