collision_layers.pyΒΆ
Part of Dungeon Explorer.
1"""Collision layers for Dungeon Explorer.
2
3A ``CharacterBody2D`` is an ordinary kinematic physics body, so two characters
4whose layers and masks mutually opt in now block each other. Dungeon Explorer DOES
5want physics separation, but only against the dungeon's static walls: enemies path
6around each other in the AI, contact damage is proximity, and a town NPC must not
7body-block the player. So each family gets its own layer, and only the wall pairing
8opts in on both sides.
9
10The canonical rule is AND: a pair collides iff
11``(a.mask & b.layer) and (b.mask & a.layer)``. That is why the wall carries an
12explicit mask naming the actor layers rather than relying on a default: opting in
13from one side only does nothing.
14
15Layer / mask are read at CREATE time, so they are passed before enter-tree.
16"""
17
18#: Static dungeon geometry (walls). The only thing anything collides with.
19LAYER_WORLD = 1
20LAYER_PLAYER = 2
21LAYER_ENEMY = 4
22LAYER_NPC = 8
23
24#: Actors sweep against the world and nothing else.
25MASK_WORLD_ONLY = LAYER_WORLD
26#: The wall's side of the same opt-in (the AND rule needs both).
27MASK_ACTORS = LAYER_PLAYER | LAYER_ENEMY
28#: "Scan no layers": a body that never sweeps and must never block one.
29MASK_NONE = 0