From 5728ebc309b4753c939d751c7fd489b108e5dc09 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Sun, 1 Mar 2026 21:52:49 +0100 Subject: fix: prevent entities from overlapping when arriving at the same cell Update UpdateMoveSystem to maintain the moveMap as entities move within a tick. When an entity snaps to a grid cell: - Block the new cell in the moveMap immediately - Unblock the old cell Before snapping, check if the target cell was already claimed by another entity earlier in the same tick. If so, repath instead of overlapping. --- physics/move.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'physics/move.go') diff --git a/physics/move.go b/physics/move.go index 94da69f..b898ec7 100644 --- a/physics/move.go +++ b/physics/move.go @@ -192,7 +192,22 @@ func UpdateMoveSystem(moveMap MoveMap, masks []ecs.Mask, moves []Move, positions *position = moveToward(*position, next) continue } + // About to snap to next cell — check it's still free + if moveMap.Blocked[next] { + slog.Info("cell blocked on arrival, repathing", slog.String("next", next.String())) + path, ok := SearchPath(*position, move.Destination, moveMap) + if !ok { + slog.Info("no path found", slog.String("destination", move.Destination.String())) + move.IsActive = false + continue + } + move.Path = path[1:] + continue + } + oldCell := Point{X: position.X / 100 * 100, Y: position.Y / 100 * 100} *position = next + moveMap.Blocked[next] = true + delete(moveMap.Blocked, oldCell) remainingPath := move.Path[1:] if next == move.Destination { move.IsActive = false -- cgit v1.3