I’m about to start writing the enemy AI for a 2D platformer. Some of the enemies will have multiple movement modes and be able to walk & fly, or walk & dash, etc.
How would you implement AI that allowed enemies to choose the most efficient movement mode(s) for travelling to a destination?
For example, an enemy that could walk & jump may choose to reach their destination by jumping from their elevated starting point before walking the rest of the way, instead of simply walking the entire way.
Pretty big discussion. I guess I would start with Youtube tutorials on the subject, although I admit it might be a) hard to search up, and b) pretty rare to find someone discussing multimodal pathfinding.
Might even be some Gamasutra or GDC articles on it. I would definitely see what others have tried.
There are certainly a lot of tutorials on pathfinding algorithms, implementing pathfinding in unity, enemy AI, etc. on YouTube and other sites. After skimming through those I have a couple of potential solutions in mind:
- Calculate multiple paths to the destination (one for each movement mode) and use them as the input for a decision tree or similar.
- Have a primary movement mode and use in-game sensors or triggers to identify when a different mode could be used
I was thinking maybe two overlaid pathing maps: airborne (or falling) and walking (or crawling).
Wherever they overlapped the AI could ask, “Which way is faster.”
He might also get tired of flying as an ability and have to alight for a while… and he’d just aim to the nearest overlap to transition to ground bound.
In the end I predict the funnest most compelling solution will be a weird mishmash of real pathing and random “do something elses…” it always seems like the best enemies play like that.
Hmmm… the problem with two separate pathing maps is that you won’t really be able to get “hybrid” navigation where parts of the path are flying and parts are walking. I think maybe a single map that allows transitions from flying to walking when near the ground. In other words, the air is a valid medium for travel, as well as the space along the ground. Let A* sort out the rest. The generated path could contain information about which parts of the path are flying parts (parts of the path through the air) and which are walking parts (parts of the path along a surface) that you can use for an animator. You could perhaps blacklist parts of the air that are nearby the ground such that the ground is actually a viable option and the character isn’t just flying all the time (especially in areas with low ceilings!).
I say all of this like it’s easy to implement, but it actually feels like a month-long project in and of itself! Good luck. Would love to see some of this in action.
1 Like
It looks like the answer might be goal oriented action planning (GOAP).
I might also maintain some flow fields & influence maps to help with the planning process.