#### Archived

This topic is now archived and is closed to further replies.

# 2D Platform AI

This topic is 5533 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi everyone, I am quite new to AI and I am currently making a 2D side scrolling platform game for a small project that I am doing for school. I have been thinking about the AI for a long time, looking at different ways of putting it together, but my major problem is the pathfinding. The basic idea is its a side scrolling game with guns and enemies, should be like worms but in real time. I''ve got most of the engine put together, and I''m starting to work on the game itself. I have decided to use a finite state machine for the AI players. I''ve got that aspect of the AI sorted, my real problem is navigating the map. There will be different platforms that players and AI will have to jump to, and thats whats causing me the problem. Say there was a power up on a higher ledge, how would the AI work out the best route to that ledge? My map I am planning to be built from a large grid of squares (tiled). Some bits will be solid and other bits will be empty (ie, you can move through them). As this is the case it should be possible for me to create a list of nodes that the AI can move between. I have looked into A*, and that would work if it is top down, but as this is a side scrolling shooter I am stuck, as I cannot work out when to jump from one ledge to another, and work out the best route to the objective. Any help you could provide me with on this subject would be much appriciated. Thank you for your time. - James

##### Share on other sites
A* is not required to work on grids, it navigates a graph.

You could simply create nodes on the ground and on your platforms, and increase the cost between connections that pass over a pit or when your character will have to jump to reach a platform.

A* will then be able to find the most optimal path to reach whatever point in the map where you added a node.

##### Share on other sites
I was aware that it did not have to be used on grids, but I hadn''t really thought of not using one.

Lets say we have a map like this:

___________________|                 || x               || ------          ||       --        ||      p    ----- ||      ----       ||_________________|

x = target, p = player

Would you basically place nodes along the tops of each platform and connect platforms that can succesfully be jumped too.. leaving ones that are too far away not connected?

That seems to work on my head, but any further clarification would help.

THanks

- James

##### Share on other sites
Yep, that's how I'd do it. I have never worked on a platformer though, so there might be some more efficient ways, but this seems perfect.

You could also create this info at runtime (during the loading phase) in case you allow the player to create his own map... by knowing the max distance the character can reach in 1 action, either horizontally or vertically you can connect the appropriate nodes together.

Eric

[edited by - xEricx on October 21, 2003 11:03:04 AM]

##### Share on other sites
Yeah, I''d had that idea already, as I am building a level editor into the game. During load time the node network will be dynamically generated depending on the map and the players characteristics.

Thanks for the help.

- James

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 10
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
633717
• Total Posts
3013509
×