How can I make an AI (artificial intelligence) for a platform game?

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • I need to know how can I make an artificial intelligence for a platform game like "Starbound" or "Terraria", where we have multiple instances of the same object and these interact individually.

    I want to do something like the example below, but with several objects (enemies) that interact with the player individually.


    Please login to see this link.

    The example is just demonstrative.


    I really appreciate any help.


    (sorry for my english)

    Hispanic Community of MMF2 and CF2.5 / Comunidad Hispana de MMF2 y CF2.5: Please login to see this link.

  • @arnever that's probably the worst way of doing it. You want the code to be flexible so that it can work will all enemy types even when adding new enemies into the game.

    You should probably use alterable values to differentiate between the copies of enemies. You can set an alterable value as an ID number. If you spread value in this variable, you can set each enemy with a different number, in case you need to specify certain enemies.

    Try to use Fusions object scope when it selects certain instances to narrow down which enemy it is effecting. An example of this would be if certain enemies are overlapping objects or comparing enemies health, etc. anything that differentiates one enemy from another.

    Usually the way I code AI, I write different "states" that the enemy can be in. Examples of these states include chasing, line of sight, searching, roaming. Try to code each section separately and use a reference number (alterable value) to switch between the states. So for example the line of sight state, it would only check enemies in a certain area around the player. That will lower the amount of enemies the game will check.

    If an enemy sees the player, you would switch the AI state to chasing. If the enemy loses the player, then it would switch the AI state to roaming. Something like that.


    Sent from my iPhone using Tapatalk

    Custom A* Pathfinding in MMF2: Please login to see this link.
    Random Tile World Generation: Please login to see this link.

  • Please login to see this attachment.

    Here is an example made by Nifflas some time ago. It's quite a bit more complex, but offers pretty much exactly what you are trying to do. Hopefully this helps.


  • I wish I could do stuff like this for my own games. It's by far my greatest weakness this side of 'the font is too small' XD

    There's a cool game I bought in Early Access on Steam called Vagante and it has really impressive enemy A.I. (IMO). Even the minor enemies will climb up ladders and do all kinds of crap to come and get you. Most of my enemies are stupid and just know how to move right and left, and occasionally turn around once they realize you're beating the crap out of them haha.

    Weebish Mines, my retro Metroidvania!
    Please login to see this link.

  • Here's the example above with multiple players:

    Please login to see this attachment.

    PMO is a great object and gives smooth results and everything,
    but I find it a bit awkward, particularly for handling multiple instances..
    ..maybe I've really never used it much and I'm just a noob with it? XD
    (is it really needed -as it would seem- to have multiple copies of it to work with multiple objects??)

    I would maybe keep it for the main player and code enemies without it, as a personal preference

    a selection of my Fusion examples can be found Please login to see this link.

  • @arnever that's probably the worst way of doing it. You want the code to be flexible so that it can work will all enemy types even when adding new enemies into the game.

    You should probably use alterable values to differentiate between the copies of enemies. You can set an alterable value as an ID number. If you spread value in this variable, you can set each enemy with a different number, in case you need to specify certain enemies.

    Try to use Fusions object scope when it selects certain instances to narrow down which enemy it is effecting. An example of this would be if certain enemies are overlapping objects or comparing enemies health, etc. anything that differentiates one enemy from another.

    Usually the way I code AI, I write different "states" that the enemy can be in. Examples of these states include chasing, line of sight, searching, roaming. Try to code each section separately and use a reference number (alterable value) to switch between the states. So for example the line of sight state, it would only check enemies in a certain area around the player. That will lower the amount of enemies the game will check.

    If an enemy sees the player, you would switch the AI state to chasing. If the enemy loses the player, then it would switch the AI state to roaming. Something like that.

    What you say is what I would like to learn to do. I've been using "MMF/CF" for a long time and I've never been able to learn on how to differentiate instances of the same objects because there are no resources about this.


    Please login to see this attachment.

    Here is an example made by Nifflas some time ago. It's quite a bit more complex, but offers pretty much exactly what you are trying to do. Hopefully this helps.

    Thanks Chaos but the file is corrupted, could you upload it again?


    Edit:

    Here's the example above with multiple players:

    Please login to see this attachment.

    PMO is a great object and gives smooth results and everything,
    but I find it a bit awkward, particularly for handling multiple instances..
    ..maybe I've really never used it much and I'm just a noob with it? XD
    (is it really needed -as it would seem- to have multiple copies of it to work with multiple objects??)

    I would maybe keep it for the main player and code enemies without it, as a personal preference

    Thanks a lot schrodinger , It is exactly what I was looking for.

    Hispanic Community of MMF2 and CF2.5 / Comunidad Hispana de MMF2 y CF2.5: Please login to see this link.

  • Here's a few tutorials explaining how object scope works in fusion. This will help you understand how to differentiate between instances.

    Please login to see this link.
    Please login to see this link.
    Please login to see this link.

    Here's a few links explaining AI states (also known as "Finite State Machines"):
    Please login to see this link.
    Please login to see this link.


    So if I were making AI for a platformer, I would have these different states (depending on the enemy type and what they are designed to do):
    -Idling
    -Roaming
    -Line of Sight (sees the player)
    -Chasing
    -Attacking

    Would the AI have to traverse dangerous areas of your level when trying to follow the player? Would the enemies have to jump at correct timings to land on other platforms? Would the enemies be confined to certain areas that they patrol in? You should try to figure out the basics of the states above in regards to a basic platforming area of your game and try to have them adapt to that. Once you have idling and roaming set up, take a look at line of sight examples if you want to include that feature.

    Here's a line of sight example that I made a month or so ago for someone else. It uses a small active object that's scaled to create a line between the enemy and the player. If anything overlaps this line, that means that the player is out of sight from the enemy. If there isn't anything overlapping the line, that means the enemy should be able to see the player. Obviously this test would only be done for enemies within a certain range of the player to minimize the amount of times you need it to run. If you're using it for multiple enemies, you could use a fastloop to check all of them very quickly. I would also add all of your enemies within a qualifier group so it applies to all of the different enemies. Here's the Line of Sight file: Please login to see this link.

    I also worked on A* pathfinding so that my enemies could find the quickest path to the player while working around obstacles. While this probably doesn't exactly fit with your game since it's a platformer, you might want to check it out since it'll give you an idea of the kind of code you could use for your game. Here's the file: Please login to see this link. . Shrodinger made a better/concise version of the pathfinding feature on my opinion. His thread is also on this forum. You can watch a YouTube video showing the example off below:

    Please login to see this media element.

    I remember seeing an old example somewhere that showed a character following another character (basically mimicking it's steps) in a platform game so that it could always follow the player as a secondary companion. It captured the player's most recent movements and coordinates and had the secondary character go though the same motions to make sure it was on the correct track. Now if you had moving platforms with different timings, this could be difficult, however I feel like you could adapt this idea for having enemies chase your character in more simple areas of your game.

    Those are a few different AI states and object scoping tutorials to think about. Let us know what kind of features that you need for your platforming game.

    Custom A* Pathfinding in MMF2: Please login to see this link.
    Random Tile World Generation: Please login to see this link.

    Edited once, last by Yves (March 12, 2022 at 7:53 AM).

  • I would like to say a massive thank you, I think I'm getting my head around it now. What stumped me was the multiple PMO's, I understand it now & I think I'm actually starting to understand loops as well. Thanks Schrodinger and Dave, very useful examples :X

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!