Chapter 7a - Areas and layers
Area2D vs bodiesβ
| Node | Collides / blocks? | Typical use |
|---|---|---|
CharacterBody2D / RigidBody2D | Solid (in real physics) | Walking, falling crates |
Area2D | Detection only | Pickups, hurtboxes, triggers |
In the kit, Area2DMock (Kit.make_area) checks circle overlap. Detection is one-way like Godot: the areaβs collision_mask must include the bodyβs collision_layer (the body does not need to βseeβ the area).
var Kit = preload("res://game_kit.gd")
var hero = Kit.make_character(Vector2(0, 0))
var coin = Kit.make_area(Vector2(10, 0), 8.0)
print(coin.overlaps_body(hero))
π§ͺ Overlap demo
Collision layers and masksβ
Godot uses bitmasks:
collision_layerβ which layers this object lives oncollision_maskβ which layers it looks for
A solid body pair interacts only if both see each other:
(A.mask & B.layer) != 0 AND (B.mask & A.layer) != 0
An Area2D detecting a body only needs:
(area.mask & body.layer) != 0
Kit helpers: area.overlaps_body(body), body.can_collide_with(other), Kit.bodies_overlap(a, b).
π§ͺ Layer mismatch
Mini quiz β areasβ
Areas and layers
1 / 3Area2D is best for
Pick an answer to see if you are right.
Challenge: claim the coinβ
Hero at (0,0) with radius = 8. Coin area at (12, 0) with radius 8. Print true if the coin overlaps the hero.
true
Exercisesβ
Activity: Too far
Hero at origin (radius 8). Area at (100, 0) radius 8. Print whether they overlap (false).
false