I’d like to have an enemy character patrol a route on a top down map. Ideally, I’d like to be able to adjust the route on the map and have some visual indication of the route.
I can think of two basic approaches:
- Use a simple list to store points defining the patrol route
- Use a group of game objects to define points on the route
Neither approach lets me see the route on the map.
I’m currently leaning towards the game object approach, the only downside is that it looks like I’ll have to maintain a list of the game object names, or use a naming standard for them that allows me to easily deduce the name of the next point on the route.
Does anyone have any suggestions for a better approach?
I would use an invisible tilemap layer with arrow tiles. The enemy would continually check the tile it’s on and react accordingly. Your tilemap editor might look something like this:
There is a simple implementation of this in my game Panic-19
https://github.com/benjames-171/panic-19
7 Likes
I love how clean your code is, perhaps I’ll get that good one day. I like the idea, and I’ll try implementing something similar.
You can also draw lines with sprites. Each segment would be a game object with a sprite and you scale it in one dimension to adjust the length of the line. You might use another sprite on each to make the joins and ends look pretty. I would have a base GO with a script and a factory to spawn line segments as needed. It could just keep a table of segment game object IDs, in order, and receive messages with a list of points for the line.
This approach might work better if your game is not tile-based, or if your patrol routes are not limited to specific angles.
Use external tilemap editor as variant. Tiled or https://deepnight.net/tools/led-2d-level-editor/
I think imitation of a patrol route like GOes for route’ points or special tile in special layer of tilemap is also good solutions, but only for small game or prototyping stage and will be a potenial pain on project with lots of things and levels.