I’m making a 2D map-based game. The player controls one character while several AI-controlled characters move as quickly as they can towards the player. The player wants to avoid them.
There are several surface types that the player and AI can move on and each has different movement bonuses. I have a color-coded map underneath the “front end” map where that will be used at each game loop to determine each character’s current speed. For example, black line segments might represent an interstate and grant a greater movement bonus than walking on the green-colored grass to the side.
I’m not a CS guy, so I want to make sure I’ve got high level AI pathfinding algorithm down. Here’s what I’m thinking:
-The enemy will always be on one type of path. We must constantly check (using the distance formula in a way that accounts for movement values of different surfaces) whether moving to an adjacent surface would be quicker than staying on the current surface. So, we must compare the two distances of (1) staying on the current surface and (2) switching to an adjacent surface.
-Use the line between the current position and target position to check what surface types will be crossed. Use this to account for your movement values in the distance formula.
What else do I need to think about?
I think what you are needing is the A* algorithm. I’m sure you can find it coded in many places, but here’s the Theorical explanation:
A* wikipedia
Sill, I think you’d be better off asking this kind of questions on Stack Overflows’ Gaming group
Here‘s a great answer from that site.