0 Favourites

I want enemies not to shoot all at the same time.

  • Greetings!

    I'm learning Construct by making a small shoot'em up.

    Actually, the game create 1 enemy every second for 6 seconds :

    http://imageshack.us/photo/my-images/201/construct1.png/

    I would like them to start shooting (for example 1 shoot every 1.2 seconds) when the are created.

    Actually, if there are 6 enemies at the same time on the screen, they all shoot at the same time.

    Any idea to change this ?

  • Try doing it with UID picking.

  • just use a "for each" loop, that should handle each instance separately, instead of having them all shoot at the same time.

    For Each Object "enemy":

    --Every "enemy2.firerate" Seconds: enemy2 - spawn bullet

  • I'll try that, thanks a lot!

  • just use a "for each" loop, that should handle each instance separately, instead of having them all shoot at the same time.

    For Each Object "enemy":

    --Every "enemy2.firerate" Seconds: enemy2 - spawn bullet

    I tried :

    http://imageshack.us/photo/my-images/152/construct2.png/

    But it doesn't seem to work, none of my enemies2 are shooting (except the "original" one outside of my layout).

    I didn't try with UID picking, I think it's a little bit complicated for me at this time. I'm a true beginner :D

  • Use a instance variable instead of "every X seconds".

    Add an instance variable to enemy2 and call it "timer". Then replace your event 12 with these two events:

    enemy2 : timer > 0

    ------- Enemy2 : Subtract dt from timer

    enemy2 : timer <= 0

    ------- enemy2 : Spawn plasmaBullet

    ------- enemy2 : Set timer to enemy2.fireRate

  • Here is an example that I did for someone who had problems with everyone shooting at the same time. Everything happens randomly. You may find it useful.

    RandomExperiments.capx

    On start of layout, creates a random number of enemy sprites at random locations, and then randomly creates new or destroys existing enemies. At random intervales choose an enemy and has it shoot in a random direction. (Ignore the part about the local variable. That was to demonstrate how to handle another problem he was having.)

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Use a instance variable instead of "every X seconds".

    Add an instance variable to enemy2 and call it "timer". Then replace your event 12 with these two events:

    enemy2 : timer > 0

    ------- Enemy2 : Subtract dt from timer

    enemy2 : timer <= 0

    ------- enemy2 : Spawn plasmaBullet

    ------- enemy2 : Set timer to enemy2.fireRate

    Thank you for this. I was having a problem using the "every x seconds" as well. It's a shame you can't combine this with (or after) a trigger that selects a single object (like "overlapping an object", or "health <= 0). Was seriously driving me crazy.

    Really though, it'd be a lot easier to use the built in timer (every x seconds) if you could have it reference each instance of an object individually, like most of the other conditions. I mean how often are you going to have multiple copies of the same object? Seems like every game has a few of those, and then to make them all not be the exact same you set some randomness. In my case I just wanted them to all jump a little different than each other, so a random timer would solve this perfectly. Too bad the built in one references all instances of the object, even if picking using a instance variable. I guess this just plays into the whole "not needing to program, template, reuse, repeat, instance based sprite system". I guess it's either been overlooked, or just isn't possible?

  • I had another thought. I understand now that "every x seconds" is a system event, so it has to be separate from the object/instance events (or that seems to be the idea anyways)

    Question:

    Could we get an additional event added to object (sprite) events list?

    -Every X Seconds

    The idea being is the same as the system events, but for the objects instead. As well as, having it be instanced (otherwise they wouldn't be different from the system version).

    I guess I've noticed that in every game I've made I've had at least one (but usually several) objects that I use in an "instanced" fashion, and giving them small randomness to their actions seems to bring a little life to the project. Not that it's hard to make a timer (now that I know how), but it'd be easier and more straight forward with an object based event option.

    Just thinking out loud...

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
378 33,248
part12studios's avatar
part12studios
Unread hot topic
167 31,097
Ashley's avatar
Ashley Construct Team Founder
Unread hot topic
234 61,207
DARKSETH's avatar
DARKSETH