---
key: lesson/collision-basics
type: lesson
id: collision-basics
lang: en
title: Collision fundamentals
summary: >-
  Separate overlap detection, physical response, and gameplay events; check
  boundaries, fast objects, and repeated damage.
updatedAt: '2026-10-20'
status: active
url: 'https://gamemechanics.pro/en/lessons/collision-basics/'
jsonUrl: 'https://gamemechanics.pro/api/v1/knowledge/en/lesson/collision-basics.json'
markdownUrl: 'https://gamemechanics.pro/content/knowledge/en/lesson/collision-basics.md'
aliases:
  - столкновения
  - коллизии
  - collider
  - collision
tags:
  - collision
  - physics
  - testing
sourceIds:
  - source-7c0748c4a86f7409
  - source-8cc54cd9f9a5c8e8
sources:
  - id: source-7c0748c4a86f7409
    title: 'MDN: 2D collision detection'
    url: >-
      https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection
    verifiedAt: null
  - id: source-8cc54cd9f9a5c8e8
    title: 'Godot: Physics introduction'
    url: >-
      https://docs.godotengine.org/en/stable/tutorials/physics/physics_introduction.html
    verifiedAt: null
relations:
  - type: requires
    direction: outgoing
    label: Before you start
    key: lesson/game-loop
    title: The game loop and time
    url: 'https://gamemechanics.pro/en/lessons/game-loop/'
    jsonUrl: 'https://gamemechanics.pro/api/v1/knowledge/en/lesson/game-loop.json'
    markdownUrl: 'https://gamemechanics.pro/content/knowledge/en/lesson/game-loop.md'
  - type: requires
    direction: incoming
    label: Continue learning
    key: lesson/level-blockout
    title: 'Blockout: test space before art'
    url: 'https://gamemechanics.pro/en/lessons/level-blockout/'
    jsonUrl: 'https://gamemechanics.pro/api/v1/knowledge/en/lesson/level-blockout.json'
    markdownUrl: 'https://gamemechanics.pro/content/knowledge/en/lesson/level-blockout.md'
  - type: requires
    direction: incoming
    label: Continue learning
    key: lesson/npc-pathfinding
    title: Pathfinding and following a route
    url: 'https://gamemechanics.pro/en/lessons/npc-pathfinding/'
    jsonUrl: 'https://gamemechanics.pro/api/v1/knowledge/en/lesson/npc-pathfinding.json'
    markdownUrl: 'https://gamemechanics.pro/content/knowledge/en/lesson/npc-pathfinding.md'
  - type: explains
    direction: outgoing
    label: Apply the principle
    key: mechanic/point-and-click--family-20
    title: 'Physics, environmental properties and experiment'
    url: >-
      https://gamemechanics.pro/en/knowledge/mechanic/point-and-click--family-20/
    jsonUrl: >-
      https://gamemechanics.pro/api/v1/knowledge/en/mechanic/point-and-click--family-20.json
    markdownUrl: >-
      https://gamemechanics.pro/content/knowledge/en/mechanic/point-and-click--family-20.md
  - type: contains
    direction: incoming
    label: Learning paths
    key: path/first-prototype
    title: Your first verifiable prototype
    url: 'https://gamemechanics.pro/en/learn/first-prototype/'
    jsonUrl: 'https://gamemechanics.pro/api/v1/knowledge/en/path/first-prototype.json'
    markdownUrl: 'https://gamemechanics.pro/content/knowledge/en/path/first-prototype.md'
  - type: requires
    direction: incoming
    label: Continue learning
    key: path/npc-behavior
    title: NPC behavior
    url: 'https://gamemechanics.pro/en/learn/npc-behavior/'
    jsonUrl: 'https://gamemechanics.pro/api/v1/knowledge/en/path/npc-behavior.json'
    markdownUrl: 'https://gamemechanics.pro/content/knowledge/en/path/npc-behavior.md'
  - type: uses
    direction: outgoing
    label: Sources in the selection
    key: resource/collision-2d
    title: 'MDN: 2D collision detection'
    url: 'https://gamemechanics.pro/en/resources/#resource-collision-2d'
    jsonUrl: 'https://gamemechanics.pro/api/v1/knowledge/en/resource/collision-2d.json'
    markdownUrl: 'https://gamemechanics.pro/content/knowledge/en/resource/collision-2d.md'
  - type: uses
    direction: outgoing
    label: Sources in the selection
    key: resource/godot-physics
    title: 'Godot: physics introduction'
    url: 'https://gamemechanics.pro/en/resources/#resource-godot-physics'
    jsonUrl: 'https://gamemechanics.pro/api/v1/knowledge/en/resource/godot-physics.json'
    markdownUrl: 'https://gamemechanics.pro/content/knowledge/en/resource/godot-physics.md'
placements: []
supersededBy: []
attributes:
  category: engineering
  level: intermediate
  minutes: 6
endsAt: null
provenance: >-
  Original gamemechanics.pro material. Check illustrative examples in your own
  project.
license: CC-BY-4.0
codeLicense: MIT
attribution: gamemechanics.pro contributors
---
# Collision fundamentals

id: collision-basics
type: lesson
key: lesson/collision-basics
lang: en
status: active
url: https://gamemechanics.pro/en/lessons/collision-basics/

Separate overlap detection, physical response, and gameplay events; check boundaries, fast objects, and repeated damage.

## Prerequisites

You need coordinates and basic conditions. Begin with two unrotated rectangles. The goal is to define exactly what contact means without confusing geometry with damage rules.

## The principle

Detection asks whether shapes intersect. Collision resolution decides how to remove penetration and change movement. Gameplay response decides what contact means: damage, picking up an item, or opening a door. These tasks can share an event while following different rules.

For axis-aligned rectangles, compare their intervals on both axes. A larger scene can first select possible neighbors and then run more precise checks. [MDN: 2D collision detection](https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection) introduces these techniques.

When using an engine, first learn its physics object types and interaction filters. The [Godot physics introduction](https://docs.godotengine.org/en/stable/tutorials/physics/physics_introduction.html), for example, distinguishes detection areas from physical bodies and explains collision layers and masks. Do not place custom movement on top of a physics solver without understanding their update order.

<span id="example-a-hazard-area"></span>

## Practical example

### A hazard area

Assume rectangle coordinates describe the top-left corner and dimensions are positive. For this exercise, touching edges without overlapping area does not count as a hit.

```text
overlap(a, b):
    separatedX = a.right <= b.left or b.right <= a.left
    separatedY = a.bottom <= b.top or b.bottom <= a.top
    return not (separatedX or separatedY)
```

Now define the gameplay rule: entering a hazard causes one hit. Keep a set of pairs that overlapped during the previous step. For each current pair, emit an entry event only if that pair was absent before. After processing, replace the previous set with the current one. Identify pairs with stable object identifiers, not positions.

This deliberately differs from applying damage every frame. If the hazard needs periodic damage, give it a separate interval measured in seconds. If a projectile must hit only once during its entire lifetime, entry history is insufficient: mark it consumed after the first accepted hit.

## Common mistakes

A visible sprite and its collision shape do not have to match exactly, but the difference should be intentional. Enable collision debugging and inspect local coordinates, scale, and anchor points.

A fast object may cross a thin wall between two discrete checks. For that case, investigate the engine's continuous collision detection, a sweep over the traveled segment, or another method suited to your shapes. Making every wall thicker hides the symptom without explaining it.

Avoid deleting items from a collection while iterating if doing so shifts the indices of objects that still need processing. Collect events, apply responses, and remove objects in a defined order. Clear stored contact information when an object is destroyed.

## Verify it

- Separated, overlapping, and exactly touching shapes produce the intended outcomes.
- A shape fully contained inside another is detected.
- Entry causes one hit; exit and re-entry follow the written rule.
- Deleting an object does not leave a stale contact.
- The fastest projectile is checked against the thinnest supported wall.
- Collision layers exclude pairs that should never interact.

## Prompt for an AI agent

> Locate collision shapes and response rules. Document the edge-touch convention, event ordering, and damage frequency. Check containment, re-entry, deletion during contact, and a fast projectile. Use the selected engine's capabilities; do not introduce a custom physics engine for a single trigger.

## Connected materials

- Before you start: [The game loop and time](https://gamemechanics.pro/en/lessons/game-loop/) (key: lesson/game-loop)
- Continue learning: [Blockout: test space before art](https://gamemechanics.pro/en/lessons/level-blockout/) (key: lesson/level-blockout)
- Continue learning: [Pathfinding and following a route](https://gamemechanics.pro/en/lessons/npc-pathfinding/) (key: lesson/npc-pathfinding)
- Apply the principle: [Physics, environmental properties and experiment](https://gamemechanics.pro/en/knowledge/mechanic/point-and-click--family-20/) (key: mechanic/point-and-click--family-20)
- Learning paths: [Your first verifiable prototype](https://gamemechanics.pro/en/learn/first-prototype/) (key: path/first-prototype)
- Continue learning: [NPC behavior](https://gamemechanics.pro/en/learn/npc-behavior/) (key: path/npc-behavior)
- Sources in the selection: [MDN: 2D collision detection](https://gamemechanics.pro/en/resources/#resource-collision-2d) (key: resource/collision-2d)
- Sources in the selection: [Godot: physics introduction](https://gamemechanics.pro/en/resources/#resource-godot-physics) (key: resource/godot-physics)

## Sources and provenance

Original gamemechanics.pro material. Check illustrative examples in your own project.

- [MDN: 2D collision detection](https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection) (id: source-7c0748c4a86f7409)
- [Godot: Physics introduction](https://docs.godotengine.org/en/stable/tutorials/physics/physics_introduction.html) (id: source-8cc54cd9f9a5c8e8)

CC-BY-4.0 · gamemechanics.pro contributors
