How do I randomize the shooting pattern for each enemy

Get help using Construct 2

Post » Fri Nov 18, 2016 8:49 am

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.

Image
B
47
S
14
G
20
Posts: 87
Reputation: 12,913

Post » Fri Nov 18, 2016 11:12 am

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 ?
B
12
S
4
G
1
Posts: 39
Reputation: 1,378

Post » Fri Nov 18, 2016 12:46 pm

DiabloOvermind wrote: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.
B
47
S
14
G
20
Posts: 87
Reputation: 12,913

Post » Sat Nov 19, 2016 3:28 am

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.
B
12
S
4
G
1
Posts: 39
Reputation: 1,378

Post » Sat Nov 19, 2016 7:38 am

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.
B
23
S
11
G
52
Posts: 137
Reputation: 27,881

Post » Sat Nov 19, 2016 11:06 am

@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 :evil: "

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
B
34
S
9
G
3
Posts: 206
Reputation: 7,851

Post » Fri Dec 02, 2016 1:23 pm

@MACPK

Thank you for providing a very informative explanation, I'm already implementing your ideas in my game using the timer behavior.
B
47
S
14
G
20
Posts: 87
Reputation: 12,913

Post » Mon Dec 05, 2016 10:05 pm

@LaroTaio Let us know if you have implemented it succesfully or if you have questions. :-)
B
34
S
9
G
3
Posts: 206
Reputation: 7,851


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 41 guests