I’m trying to implement a top-down Zelda-like enemy movement system. Consider a screen of x tiles wide by y tiles tall, each tile being 16x16 pixels.
I’m not asking for code here. I’m asking for direction. I’m using Godot, but perhaps the answer isn’t engine specific. Should I use something akin to NavigationAgent2D? Or manual movement? Based on the requirements below what is the best practice for an enemy movement system?
Requirements:
- Enemies can only move in cardinal directions (up, down, left right).
- Enemies cannot enter tiles that have physics colliders.
- Enemies are confined to the current screen and must not leave the screen.
- Enemies may or may not pass through each other (based on enemy type).
- Enemies may or may not be inclined to move toward the player (based on enemy type). Even if they move toward the player, they must still respect cardinal direction movement.
- Enemies can be hit with melee or ranged weapons which apply a force to them. The force should apply to them if hit from the same or opposite direction that they’re moving.
Most tutorials just have pathfinding where enemies take the shortest route to the player. But I want my enemies to move around the screen in confined cardinal directions and be mostly oblivious to the the player, like in Zelda. But I keep running into problems where they get stuck or do not keep their movement aligned with the tile grid.
As I see it, enemies decide a direction to move and how many tiles to move, and then when they reach their destination tile they must decide again. But I could be going about this wrong. Other enemies (or the player) could get in the way and they’d be forced to recalculate their next move. It’s important that they stay aligned with the grid.
Is there some built-in node or system in Godot that can be used to satisfy these requirements?
Any suggestions are truly appreciated.