Advertisement

2D path finding ....

Started by January 29, 2009 07:39 AM
1 comment, last by gameplayprogammer 15 years, 9 months ago
I have an enemy character that is following the human player. I want the enemy to jump onto platforms if the human player jumps on to one. At the moment i am doing it by recording the human players position every second in a list, then picking the oldest position on that list and moving the enemy towards it. The list only stores the last 5 human player positions and removes the rest. I want a better way of doing this, a more independent way of the enemy finding a path onto a platform. At the moment the enemy mirrors the human players movement. Any help on this? It must be quite a common problem. BTW it is in 2D, for now anyway.
I was doing something like this a while ago - I went with generating a navigation mesh and running A* over it to find the best path between two points. The nav mesh was generated at level load time something like:

1. Generate waypoints: add waypoints at the start, end and middle of all platforms (multiple middle waypoints for long platforms).
2. Connect waypoints on the same platform to each other with bi-directional links (for running).
3. Connect waypoints to any nearby waypoints on different platforms with bi-directional links (for jumping)
4. Connect waypoints to waypoints roughly below them with single directional links (for dropping down from a high platform to a low one).

The end result looked like this (although this is without step 4 IIRC):


Then at runtime you just have to find the nearest waypoint to the player and enemy and run A* over the nav mesh to calculate the best path. Then just move the enemy along it, either running or jumping depending on whether the next waypoint is on the same surface as you're currently standing on or a different one.

Hope that helps.
Advertisement
Thanks for the response it is a real help, this is much better than doing it dynamically. will try it out.

This topic is closed to new replies.

Advertisement