How do I randomize the shooting pattern for each enemy

0 favourites
  • 8 posts
From the Asset Store
Shoot balls to destroy as many blocks as possible, at each stage the game will become more difficult.
  • How to randomize the shooting pattern for each enemy independently with line of site behavior?

    I noticed when the two enemies(copied from same object) has the line of site of the player the shooting pattern is the same or they shoot at the same time, is there a way that I can make each enemy to shoot bullets randomly with different time pattern?

    I even tried adding For Each Enemy on the event condition but the problem is, only one enemy is shooting one at a time until the player is out of site from one enemy before the other enemy starts to shoot.

  • Might be a stupid answer (im a very basic user), but you could try to use the UID of your enemies to make their shooting frequency look "random", try to use this maybe ?

    Enemy has Player in LOS

    --System : Every "EnemyUIDvalue+somethingrandom" => Spawn bullet

    What do you think ?

  • Might be a stupid answer (im a very basic user), but you could try to use the UID of your enemies to make their shooting frequency look "random", try to use this maybe ?

    Enemy has Player in LOS

    --System : Every "EnemyUIDvalue+somethingrandom" => Spawn bullet

    What do you think ?

    I've got 10 enemies, what will I put on the UID value?

    I'm still a newbie as well, I tried your idea but it didn't work, would be nice if you can provide a screenshot or better yet a sample working capx.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Well im sorry man, I tried it myself too, and indeed it didnt work. I thought using the enemy UID (which is a different number for every single enemy) would make them all shoot at different times, but it takes every single enemy instead of all of them separately.

    I think a good way around would be to use the 'pick' system event. But I am myself struggling with this command. But this must be your solution, try to modify your sub event by adding a 'pick' condition to it, and experiment with it, you should end up finding your solution.

    Sorry I couldnt help.

  • You could add the turret behavior to the enemies and have it initially disabled, and then when enemy has LOS enable turret behavior, and when enemy loses LOS disable the turret behavior. You would have spawn the enemy bullet 'on shoot' under the turret events. This will work, as long as I didn't forget some detail.

    This is the technique I use in my current project Escape is Possible. If you'd like to see it in action then click the link in my signature.

  • LaroTaio

    Who many enemies will be on screen? I think this part of code could produce overhead. E.g. if there are 10 enemies on the screen they will all check every tick if they have line of sight. With the second part you want to create the alteration of time between two shots. I would recommend to use a "timer" for it. So when an enemy shoots you set a timer for "not being idle to shoot / reloading / waiting" (however you want to call it^^). Timers trigger automatically a state as soon as done. So you can not only use it for something like a bomb (trigger on finished) but for "is not counting down / blocked" right now. I would do it like this:

    Every 0.1 seconds

    -> check for enemies that are not "reloading" then

    --> check if they have "line of sight"

    If both is true spawn a bullet (shoot) and activate the timer of that enemey with a random number. I think sometimes it helps to try to put the code in human readable sentences or scenarios. E.g. your code above says:

    the system is stressed and asking ten enemies on the layout every tick: "hey guys, do you have line of sight towards the player?" - three say "yes" and think (may we should? we are idle, never fired ever before). Seven say "no" (we don't see the player) The system want to give the order to fire but wait! System is cheking its watch and says: "sry guys, we can only shoot if the pointer for seconds is at 12 because you need time to reload. this will be in 6 seconds but never mind I will ask you 360 (60 ticks x 6 seconds) times until then if you have line of sight but won't give the order to fire". Enemies: "we don't need to relaod <img src="{SMILIES_PATH}/icon_evil.gif" alt=":evil:" title="Evil or Very Mad"> "

    So the core question is why should everybody wait together. By timer you can tell single enemies to reload (wait). It doesn't matter if they have line of sight. So to give my example as a story:

    the system is chilled and asking ten enemies on the layout every 6 ticks: "hey guys, please, everybody that is not currently reloading listen to me". All of them are answering "hey, we are idle" (but if some would say reloading that enemies would not listen anymore. The system says: "please check if you have line of sight to the player". Two enemies answer "yes, we do". system says: "ok fire and then you wait/reload". The system is randomly giving these two enemies tickets with numbers on it which says "reload 1 second" or "reload 2 seconds".

    https://www.scirra.com/manual/167/timer

  • Thank you for providing a very informative explanation, I'm already implementing your ideas in my game using the timer behavior.

  • LaroTaio Let us know if you have implemented it succesfully or if you have questions.

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