1.9 KiB
1.9 KiB
MEMORY.md — Durable Facts & Decisions
Godot 4.7 — Stage 2 TileMapLayer collision (verified in headless)
- TileSet + TileMapLayer + polygon collision WORK in Godot 4.7 headless. Verified: Fox drops onto a TileMapLayer tile and lands at the tile's polygon top edge (steps=13, vel.y=0, on_floor=true).
- Headless physics pattern: run via
flatpak run org.godotengine.Godot --headless --path .withrun/main_sceneset to a scene whose root is aNode2Dscript with_ready()+_physics_process(delta). The engine's main loop drives physics (no need forPhysicsServer2D.step()/integrate_forces). - Two headless gotchas for TileMapLayer:
- The moving body (Fox) must be a direct child of the root Node2D, NOT nested inside the
TileMapLayer. A Fox nested inside TileMapLayer gets a null physics space (body->get_space()null → move_and_slide no-ops) and falls forever. - Fox must start above the tile polygon. TileSet polygon points are in tile-local coords with the tile's top edge at y=0 and downward positive. If Fox starts below y=32 it's already past the tile and falls away. Start at negative y.
- The moving body (Fox) must be a direct child of the root Node2D, NOT nested inside the
- Per-tile collision polygon API (Godot 4.7):
TileSet.add_physics_layer()(void, auto-indexed),set_physics_layer_collision_layer(idx, mask),set_physics_layer_collision_mask(idx, mask).TileMapLayer.get_cell_tile_data(Vector2i coords)→TileDataobject (returns a live/mutable ref; edits persist — verified re-read = 1).td.set_collision_polygons_count(layer_index, count),td.set_collision_polygon_points(layer_index, polygon_index, PackedVector2Array([...])).get_cell_tile_datais the correct accessor; there is NOset_tile_dataon the atlas source and noTileSetCollisionObject2D.
add_childis onNode(notWorld2D);get_root()returns aWindow, notNode2D. Use aNode2Dscript as scene root for physics.