25.6 C
New York
Sunday, August 31, 2025

ai – Enemy motion system on a 2D grid (Zelda-like)


I’m attempting to implement a top-down Zelda-like enemy motion system. Think about a display screen of x tiles broad by y tiles tall, every tile being 16×16 pixels.

I’m not asking for code right here. I’m asking for path. I’m utilizing Godot, however maybe the reply isn’t engine particular. Ought to I exploit one thing akin to NavigationAgent2D? Or guide motion? Based mostly on the necessities under what’s the greatest observe for an enemy motion system?

Necessities:


  • Enemies can solely transfer in cardinal instructions (up, down, left proper).
  • Enemies can’t enter tiles which have physics colliders.
  • Enemies are confined to the present display screen and should not depart the display screen.
  • Enemies might or might not go via one another (based mostly on enemy kind).
  • Enemies might or will not be inclined to maneuver towards the participant (based mostly on enemy kind). Even when they transfer towards the participant, they have to nonetheless respect cardinal path motion.
  • Enemies could be hit with melee or ranged weapons which apply a power to them. The power ought to apply to them if hit from the identical or wrong way that they’re transferring.

Most tutorials simply have pathfinding the place enemies take the shortest path to the participant. However I need my enemies to maneuver across the display screen in confined cardinal instructions and be principally oblivious to the the participant, like in Zelda. However I maintain working into issues the place they get caught or don’t maintain their motion aligned with the tile grid.


As I see it, enemies resolve a path to maneuver and what number of tiles to maneuver, after which after they attain their vacation spot tile they have to resolve once more. However I could possibly be going about this flawed. Different enemies (or the participant) may get in the best way they usually’d be pressured to recalculate their subsequent transfer. It’s essential that they keep aligned with the grid.

Is there some built-in node or system in Godot that can be utilized to fulfill these necessities?

Any recommendations are actually appreciated.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles