Help with AI

FlayrFlayr Member Posts: 3
edited July 2012 in Working with GS (Mac)
I encountered a problem so I created a new project just to find the solution, only including the behaviors relavent to my problem for simplicity. I created two actors Player and Enemy. Player can move around a level with the arrow keys and its x and y attributes are set to Game.PlayerX and Game.PlayerY. The enemy has a "Move" behavior that makes it always move forward at a rate of 15. It also has a "Rotate to Position" attribute set to the "PlayerX" and "PlayerY" attributes as the position and 20 as the speed. The Enemy does chase the Player but when I put more than one on the field they run into each other and tur into one blob of enemies. I need to know how to make them not run into each other but still chase the Player. Another important thing is making the enemies avoid obstacles (walls etc.) so they dont constantly bash into them and get stuck.

Thanks in advanced (assuming someone does help) for my game could not be completed without this solved.
-Flayr

Comments

  • quantumsheepquantumsheep Member Posts: 8,188
    Give your enemy actor and wall actor the tag 'Obstacles' or whatever you want to call it.

    You could then put a 'collide' behaviour in your enemy and walls that says 'Collide with actors with tag 'obstacles'.

    Try it. It should make sure that they stop being a big blob and can move 'around' walls and stuff to get to the player.

    Might work.

    QS

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • ironDanironDan Member Posts: 148
    Making the enemy collide with each other will definantly make sure you don't have a giant blob of enemies, but when they collide with walls and your player is on the other side of a wall from the enemy, the enemy will just stay there at the wall and not look for an alternate route to find your player since it is coded to just move in a straight line to the player. For a proper AI you need to create a Pathfinding algorithm like A*. The only problem with that is Gamesalads Tables are not complete and is very difficult to accomplish without a lot of creative thinking.
  • FlayrFlayr Member Posts: 3
    Give your enemy actor and wall actor the tag 'Obstacles' or whatever you want to call it.

    You could then put a 'collide' behaviour in your enemy and walls that says 'Collide with actors with tag 'obstacles'.

    Try it. It should make sure that they stop being a big blob and can move 'around' walls and stuff to get to the player.

    Might work.

    QS

    That worked for the enemies layering over each other and making obstacles stop enemies. However I wold prefer for enemies to try to avoid both and not actually collide. Another thing, when the actor collides with an obstacle the obstacle gets pushed. Is there a better way to stop this besides making it always take the same coordinates with a behavior?
  • FlayrFlayr Member Posts: 3
    Making the enemy collide with each other will definantly make sure you don't have a giant blob of enemies, but when they collide with walls and your player is on the other side of a wall from the enemy, the enemy will just stay there at the wall and not look for an alternate route to find your player since it is coded to just move in a straight line to the player. For a proper AI you need to create a Pathfinding algorithm like A*. The only problem with that is Gamesalads Tables are not complete and is very difficult to accomplish without a lot of creative thinking.
    Thanks for the input. Any ideas for how to make the pathfinding algorithm or where to find a guide for something similar to what I am attempting?
Sign In or Register to comment.