Enemies not stopping at correct distance nor attacking at the same time.

0 favourites
  • 9 posts
From the Asset Store
An educational game for Times Table. An easy to use template for developers to build larger games
  • Hi all,

    Recently I got back to using Construct 2 and I am playing around with enemy AI. I am trying to create an enemy that basically does this:

    - On spawn, it pathfinds to player.

    - When it sees player it checks distance; if it is within attack range.

    --- if yes, then attacks the player periodically (i.e. every x seconds based on its attack speed).

    --- if no, then continue to pathfinds till it reaches its attack range.

    - If player moves away (further than attack range) from the enemies, they go back to pathfinding towards the player.

    Another thing I'd like to do is not have enemies overlap on each other when they reach the player (like you see them in the GIF below). I haven't addressed that yet, because I am not sure exactly how to do that in Construct 2.

    This the event sheet:

    i.imgur.com/FYmzmqh.png

    This is the bahaviour I get:

    i.imgur.com/fZ6wRxj.gif

    First off they don't stop at the range I set in LoS (50) they stop RIGHT on top of the player. Second thing is that if I watch the player's HP to check the attacks, all I find is that the HP is being deducted as if one enemy is attacking. In the GIF there are 4 enemies (2 are overlapping each other) and yet when an attack happens HP goes down from say 10 to 8 instead of instantly to 2. Do I have to use a for loop for the attack?

    Not sure what I am doing wrong exactly. Any ideas?

    Thanks in advance.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I don't see the image of your event sheet.

    There are many ways to do all this, try searching the forum and tutorials.

    Here is a recent topic:

    construct.net/en/forum/construct-3/how-do-i-8/keep-followers-spaced-one-153220

    I also have a few demos, they are for Construct 3, you should be able to open them in the free version and maybe copy some ideas to your game.

    howtoconstructdemos.com/avoid-overlapping-while-moving-with-pathfinding

  • I don't see the image of your event sheet.

    There are many ways to do all this, try searching the forum and tutorials.

    Here is a recent topic:

    https://www.construct.net/en/forum/construct-3/how-do-i-8/keep-followers-spaced-one-153220

    I also have a few demos, they are for Construct 3, you should be able to open them in the free version and maybe copy some ideas to your game.

    https://howtoconstructdemos.com/avoid-overlapping-while-moving-with-pathfinding/

    I have updated the original post with a link from imgur so you can see the event sheet now. Not sure what is up with Construct's website.

    I checked the first link you posted and that is something I did at one point and it just still overlapped most of the time. Even when I added a delay at the start (before they start pathfinding) and providing a random X and Y offset that is deducted from the player's position.

    I'll see if I can recalculate a position if they are going to overlap with another agent.

    Your dropbox links won't download. I tried on multiple browsers but I get the same exact error message saying "There was an error trying to download this file" even after clearing my Chrome's cache not sure what is up with that.

  • In your screenshot you need to add "For each BasicMeleeFollowEnemy" condition to event #3.

    Your dropbox links won't download.

    This is odd, I checked on another machine and they are working. Try direct links:

    dropbox.com/s/nndzbogyc0dz2wt/Pathfinding_NoOverlapOnDestination.c3p

    dropbox.com/s/gmvzgg6trvsfipu/Pathfinding_NoOverlapWhileMoving.c3p

  • In your screenshot you need to add "For each BasicMeleeFollowEnemy" condition to event #3.

    > Your dropbox links won't download.

    This is odd, I checked on another machine and they are working. Try direct links:

    https://www.dropbox.com/s/nndzbogyc0dz2wt/Pathfinding_NoOverlapOnDestination.c3p?dl=0

    https://www.dropbox.com/s/gmvzgg6trvsfipu/Pathfinding_NoOverlapWhileMoving.c3p?dl=0

    Still not working, I think it might be something on my end with Dropbox; One Drive and Google Drive work just fine.

    Wouldn't the For Each BasicMeleeFollowEnemy" pick all of the enemies whether they are nearby or not? Do I have to do a Pick All condition first?

  • Add "For each BasicMeleeFollowEnemy" as a second condition, directly under "BasicMeleeFollowEnemy has LOS.." in event #3. It should fix the issue with attacking and chasing.

  • Add "For each BasicMeleeFollowEnemy" as a second condition, directly under "BasicMeleeFollowEnemy has LOS.." in event #3. It should fix the issue with attacking and chasing.

    Gotcha, thank you very much! Would you know why the enemies won't stop where the distance is set and they go directly to the player location?

  • You probably need to add "Pathfinding Stop" action to event #4.

    By the way, instead of checking the distance in that event, you can set the distance in LOS properties.

  • You probably need to add "Pathfinding Stop" action to event #4.

    By the way, instead of checking the distance in that event, you can set the distance in LOS properties.

    Huh! Nice catch, I thought I had that there. Thanks for the solution.

    As for not checking the distance, that is a good point. It is a test at the moment as this AI is basically following the player from the moment it spawns; another might be just far and won't move until it actually sees the player and up till it reaches its attack range then attack.

    But for this one, spot on, yes, thanks for that. I'll remove the distance and depend on LOS' range.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)