Why not all enemies are attacking?

0 favourites
  • 12 posts
From the Asset Store
Pixel Enemies for SHMUP consists of 38 enemy ship sprites to be used in your game.
  • Hey all,

    So I am working on AI for my enemies and I am facing a issue and I am not exactly sure of its solution. First off, here is my AI "code"

    The problem is that not every enemy of this type is actually following the AI code. I have about 5-7 enemies on the layout. They all follow the "Find path" part towards their targets. They all reach the targets and stop within the distance "attackRange". However, of the 5-7 enemies, only about 1-2 shoot their targets while the rest are just standing their doing nothing. Any idea what is wrong?

    Note: I am using Find Path every 0.2 seconds because the target is moving and don't want the enemy to pathfind to an old position.

    Tagged:

  • Perhaps a rounding error at the edge of the attack range? Maybe have them stop after they are slightly closer.

  • Perhaps a rounding error at the edge of the attack range? Maybe have them stop after they are slightly closer.

    I don't think so because the targets move so sometimes they get closer to the enemies anyway and still no attacking happens. I also just tried adding a wait > 0.2 seconds just before stopping (should be enough to decrease the distance) but no change.

  • Have you tried disabling the first else event just to see if it is interfering?

    Also is the basicrange.attackspeed a fixed value and is it correctly set on all of your instances?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Have you tried disabling the first else event just to see if it is interfering?

    Also is the basicrange.attackspeed a fixed value and is it correctly set on all of your instances?

    If with the first else you mean the one with Every 0.2 seconds as a sub event, I did that. Same issue, but a new one crops up where if the target moves away, now the enemy doesn't follow it.

    If you mean the one with the pick random villager, then I did that and the enemies don't pick a random villager and stay put after the villager they were going after stops.

    I am pretty sure they all have the proper values since I set it in the Project hierarchy and not individually. But I double checked and selected them all one by one and they have the proper values -- 300.

    That said, there is something I noticed that some of the enemies do when the game starts stand there doing nothing they are in a "moving along the path state" but not moving. At least I am guessing so because they are doing an animation that is ONLY triggered when the enemy moves along the path. I don't know what is going on there.

  • Ok. It's too hard to troubleshoot without seeing the project file. Upload it and I'll take a look

  • Ok. It's too hard to troubleshoot without seeing the project file. Upload it and I'll take a look

    Here is the .c3p file:

    https://www.dropbox.com/s/4f401hx6oj3e36n/Defendor.c3p?dl=0

    Thanks.

  • Hope this is OK, but bumping as I am still not sure how to fix this. :/

  • Hey, sorry for leaving you high and dry there I had some unexpected work come up.

    I have redone your ranged enemy event sheet to show you how to set up the events for what you wanted.

    **Please do not save over your existing work with as I've deleted some other things just to make it easier for me. You will need to create the instance variables I have created and then copy the event sheet across.

    1drv.ms/u/s!AkmrWgxeuxlKhIcbo9J75qqxC1NPvA

    The majority of your problems were just incorrect picking events and the use of "for Each" in the wrong spots meaning that it would wait for one instance to complete a bunch of stuff before it would move onto the next one.

    See the notes in the project file for more info on what I have done :)

  • Hey, sorry for leaving you high and dry there I had some unexpected work come up.

    I have redone your ranged enemy event sheet to show you how to set up the events for what you wanted.

    **Please do not save over your existing work with as I've deleted some other things just to make it easier for me. You will need to create the instance variables I have created and then copy the event sheet across.

    https://1drv.ms/u/s!AkmrWgxeuxlKhIcbo9J75qqxC1NPvA?e=UcKtc2

    The majority of your problems were just incorrect picking events and the use of "for Each" in the wrong spots meaning that it would wait for one instance to complete a bunch of stuff before it would move onto the next one.

    See the notes in the project file for more info on what I have done :)

    No problem, the bump was just a general bump not trying to push you to post earlier. Sorry if it sounded that way. Thank you VERY much for fixing the issues in the project.

    If you don't mind I have a few questions, since I thought I understood how these things worked better than this.

    - Let's start with the simple one; wouldn't 3 For Each loops be an issue performance wise?

    - Same question for picking, we're doing lots of picking in this event now. Won't that be an issue performance wise since it has to pick ALL instances then filter through them? Doing that multiple times isn't an issue? Let's say I have about 100 enemies on the screen at any given one point and about 10 villagers as a worst case scenario (this of course excludes GUI, background elements, objects and VFX).

    - Is setting UID to -1 wrong? I am asking because I saw you set it to 999 and I wasn't sure if UID can be set to -1 or not.

    - Why did you do the pathfinding this way?

    https://imgur.com/NPSyqyP

    Didn't the part that says "Pick Villager" in the screenshot above already picked the villager? Why not use that then to pathfind directly instead of saving its location for later to pathfind to separately?

    I am asking because I am trying to understand the mode of thinking so I can modify my own.

    Thanks

  • Hey that's alright I didn't take it that way at all. To address your questions:

    wouldn't 3 For Each loops be an issue performance wise?

    No is the simple answer. Anything can be a performance issue in right situation. You can certainly measure the performance impacts of opposing ways of doing things if you want to. If you use a for each loop at the top of an event hierarchy then everything in that hierarchy has to be tested for each. If you use multiple for each loops for specific elements of the event hierarchy then only those elements have to be tested for each.

    we're doing lots of picking in this event now. Won't that be an issue performance wise since it has to pick ALL instances then filter through them? Doing that multiple times isn't an issue?

    There are only 5 pick events in the sheet and they are not all always running so I would not call that lots of picking :) The rest is the same as what I wrote in the first answer, anything can be a performance issue.

    Is setting UID to -1 wrong? I am asking because I saw you set it to 999 and I wasn't sure if UID can be set to -1 or not.

    Don't know. Try it! :) I just picked 9999 cause that's what I use. Obviously if you have 10000 UID's then you'd need a different number

    Why did you do the pathfinding this way?

    I assume you're referring to the event that sets the targetX and targetY variables? If so it is so that you do not need to reference or pick the villager again in any subsequent events. The enemy instance always has the variables provided they have a target. For example if you stopped the pathfinding and needed to find a path again, you would need another event that picked the right villager to get the coordinates to.

    You should remember that there are heaps of different ways to achieve this result. This just happens to be the way that I went, it certainly wouldn't be the fastest or most performant because If I spent more time on it I would refine and test vs opposing ways etc. So if performance is an issue for you, what you have is a working system that you can now go and compare against other methods to find the quickest.

    Hope that answers your questions

  • Hope that answers your questions

    Very much so, thank you very much. I'll try to adjust to this new mode of thinking. Also just in case, my questions regarding performance were just to get to understand C3 more. I still don't know its performance boundaries and best practices -- the questions were to learn that is all. Thanks a lot again for being thorough with your explanation and fixing my project :D

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