Skip to content
AI-powered appsNewChat, vision, voice, generationBookings & schedulingAppointments that book themselvesShops & sellingA storefront in every pocketClient & businessRun the operation from one placeCommunities & clubsA home that is not a group chat
Health & wellnessHabits, tracking and calmGames2D, 3D and multiplayerPersonal & toolsThe tool you wish existedInternal toolsThe tool ops never had time for
See all use cases
ArcadeNewPricingSecurity
EngineThe game engine and World EditorHow it worksFrom one sentence to a live productDocsGuides for building and publishingBlogStories, guides and newsChangelogWhat shipped latelyStatusUptime of every serviceSupportGet help from the team
AI-powered appsBookings & schedulingShops & sellingClient & businessCommunities & clubsHealth & wellnessGamesPersonal & toolsInternal tools
See all use cases
ArcadeNewPricingSecurity
EngineHow it worksDocsBlogChangelogStatusSupport
Language
Blog
GlossaryNovember 22, 20263 min read

What is collision detection?

Detecting that two shapes overlap is easy. Doing it for hundreds of objects, at speed, without things passing through walls, is the real topic. Here is the short version.

Startbase Team
Editorial ink illustration of two wooden marbles about to touch on a tilted tray, the meeting point in ember orange

Key takeaways

  • Collision detection answers "do these two shapes overlap?"; collision response decides what happens next (stop, bounce, take damage).
  • Most 2D games need only two tests: rectangle against rectangle (AABB) and circle against circle.
  • Fast, small objects can tunnel through thin walls between frames; swept checks, raycasts or smaller physics steps fix it.

Whenever a game needs to know that two objects are touching or overlapping (a player landing on a platform, a ball hitting a brick, a bullet striking an enemy), the code that answers that question is called collision detection.

Walking through a dark room with your hands out is collision detection with a body. Your hands report "something is here"; deciding to stop, step around it or sit down on it is a separate choice. Games split the work the same way: detection first, response second.

The two tests most games need

Games compare simple stand-in shapes, the hitboxes, rather than detailed art. Two checks cover most 2D games:

  • AABB (axis-aligned bounding box): two unrotated rectangles overlap when they overlap on both the x axis and the y axis. Four comparisons. Perfect for tiles, platforms and boxy characters.
  • Circle vs circle: two circles touch when the distance between centers is less than the sum of their radii. Compare squared distances to skip the square root. Ideal for balls, bullets and round enemies.

Rotated boxes, polygons and 3D meshes need heavier math (separating axis tests, for example), which is one reason to hand that work to a physics engine.

Broad phase and narrow phase

Checking every object against every other grows fast: 200 objects means about 20,000 pairs per frame. Games cut that down in two phases. The broad phase cheaply rules out pairs that cannot possibly touch, using a grid or by sorting objects along an axis, so a bullet only checks enemies in nearby cells. The narrow phase runs the exact test on the few pairs left. Tile-based games get a free broad phase: to see if the player hits a wall, look up only the tiles under the player's box (tilemaps explained).

Response, and the tunneling problem

Once an overlap is found, the game resolves it. For walls the usual method is to push the object back out along the shortest direction, moving on x and y separately so a player sliding along a floor does not snag on the seam between two tiles. For bouncing, flip the velocity on the axis that hit. For damage, trigger the hit once and ignore further overlap for a moment.

The classic bug is tunneling: a fast bullet is in front of a thin wall on one frame and behind it on the next, so no frame ever sees an overlap. Fixes, in order of effort: keep walls thicker than the fastest object moves in one frame, split movement into smaller sub-steps, or cast a ray along the path (a raycast).

Collisions in a Startbase game

The agent writes collision code for 2D games and can use Rapier physics in 3D games. The bugs you will notice are behavior bugs, so describe the behavior: the player sticks to walls when jumping into them, the ball passes through the paddle at high speed, the character catches on tile edges.

The ball sometimes passes through the paddle when it is moving fast. Use swept collision or sub-steps so it can never tunnel, resolve wall collisions on the x and y axes separately, and add a debug view that outlines every collider.

Common confusions

  • Collision vs trigger. A trigger detects overlap without blocking: a checkpoint flag, a door zone. Same detection, no push-back.
  • One-way platforms. They collide only from above and only when falling, a response rule rather than a detection trick (moving and one-way platforms).
  • Pixel-perfect collision. Comparing actual pixels is slow and rarely feels better. Tuned boxes win almost every time.

For genres where collisions are the whole game, see how to make a breakout game and how to make a physics puzzle game.

Frequently asked questions

What is AABB collision?

AABB stands for axis-aligned bounding box: an unrotated rectangle. Two AABBs collide when their ranges overlap on both the x and y axes, which takes four comparisons.

Why do objects sometimes pass through walls?

They move far enough in one frame to skip the wall entirely, called tunneling. Thicker walls, smaller movement steps or swept and ray-based checks prevent it.

Do I need a physics engine for collisions?

Not for most 2D arcade games: rectangle and circle checks are enough. A physics engine pays off for stacking, rolling, rotation and realistic bounces.

On this page

  • The two tests most games need
  • Broad phase and narrow phase
  • Response, and the tunneling problem
  • Collisions in a Startbase game
  • Common confusions

Keep reading

More in Glossary
Editorial ink illustration of a hand-cranked music box drum plucking a metal comb, the crank handle in ember orange
GlossaryNovember 22, 2026

What is a game loop?

Every real-time game runs one repeating cycle: read input, update the world, draw it. Here is what that cycle looks like and why it decides how your game feels.

3 min read
Editorial ink illustration of a brass stopwatch beside a small wind-up toy car, the second hand in ember orange
GlossaryNovember 22, 2026

What is delta time?

Delta time is the number that keeps your game the same speed on every screen. Here is how to use it, where it breaks, and how to spot a game that forgot it.

3 min read

Read less. Ship more.

Everything in this post is one prompt away. Describe your app and watch it build.

Start building

Apps, games, backends and publishing from one conversation.

Product

  • Features
  • Use cases
  • Pricing
  • Changelog

Resources

  • Blog
  • Docs
  • Support
  • Status
  • Security

Contact

  • w@startbase.ai
  • X / Twitter
  • LinkedIn
  • Instagram

Legal

  • Terms
  • Privacy

© 2026 Startbase. All rights reserved.