HeadlinesBriefing favicon HeadlinesBriefing.com

Godot Devlog: Fish AI Movement

DEV Community •
×

A developer's journey into creating believable fish movement for a cozy tank management game reveals the complexities of AI pathfinding. Initial experiments in Godot used simple random direction changes, but fish quickly got stuck on boundaries and each other. The first fix introduced separation behavior, pushing fish apart when they got too close.

However, this created new problems where fish would get trapped in infinite turning loops, constantly trying to avoid one another. The breakthrough came after researching navigation agents. The developer switched from manual steering to Godot's built-in `NavigationAgent2D` system, which handles pathfinding and obstacle avoidance automatically.

This required rewriting 80% of the fish script but resulted in much smoother, more natural movement. The final implementation also added a finite state machine and energy management, creating a more robust system that's easier to maintain and extend for future game mechanics.