Explore key techniques and logic behind 2D collision detection in browser games. This quiz highlights foundational principles, detection methods, and common challenges encountered while building interactive gameplay mechanics.
When detecting if two axis-aligned rectangles overlap in a 2D browser game, which condition best determines if a collision has occurred?
Explanation: To detect a collision between two axis-aligned rectangles, you must check if they overlap on both the X and Y axes. If either axis does not overlap, the rectangles are not colliding. Rectangle areas or matching centers do not demonstrate an overlap, only coincidental alignment or size. Proportional widths and heights may make the shapes similar but do not indicate collision.
Which mathematical approach is commonly used to detect a collision between two circles in a 2D game?
Explanation: For circle-to-circle collision, you compare the distance between the centers to the sum of the radii; if the distance is less than or equal, a collision has occurred. Equal circumferences or shared points are not reliable for collision detection. While bounding boxes can be fast to check, they are less accurate for circles and may produce false positives.
Which statement accurately contrasts pixel-perfect collision detection with bounding box detection in 2D browser games?
Explanation: Pixel-perfect detection checks individual pixels and is highly precise but slower, while bounding box detection is faster but less accurate due to its generalization. Pixel-perfect detection is not limited to rectangles and bounding box can apply to any shape. Only pixel-perfect requires per-pixel analysis; bounding box checks do not.
After detecting a collision between two objects in a 2D browser game, which is an appropriate initial response to prevent overlapping?
Explanation: The standard initial response to a collision is to resolve overlap by moving objects apart until their boundaries just touch, preventing further intersection. Increasing velocities or resizing does not stop the overlap. Changing colors only gives visual feedback and does not solve the physical collision. Proper collision response maintains logical game interactions.
What can often cause 'tunneling' in fast-moving 2D objects with simple collision detection algorithms?
Explanation: Tunneling occurs when an object moves so fast that it passes through another object between frames, missing collision checks entirely. Sprite rotation or canvas size do not inherently affect tunneling. While gravity impacts movement, a value of zero does not specifically cause tunneling; the issue is related to update frequency and object speed.