Enemy AI: chasing a player without Navigation2D or A* pathfinding
game-aipathfindinggodotstate-machinesenemy-behavior
Abstraction: Scent-trail raycast technique for obstacle-aware enemy chasing in Godot 2D
Key points:
- Problem: direct-chase AI (move toward player position) gets stuck against obstacles
- Solution: player drops "scent" Node2D instances every 0.1s into a trail array; scents auto-expire via Timer
- Chase state raycasts directly to player first; if blocked, iterates the scent trail to find the nearest visible scent node and chases that instead
- Uses Godot KinematicBody2D, RayCast2D, Physics Layers for collision filtering, and a State Machine architecture
- Lightweight alternative to built-in Navigation2D or AStar nodes; used in production game Helms of Fury
- Scents stored front-to-back (most recent first) so enemy follows the freshest visible trail toward the player
Connections: Godot Engine · Game AI · Pathfinding · State Machines