Alternating Shots/Random Instance [C2] [SOLVED]

0 favourites
  • 11 posts
From the Asset Store
Easily generate many levels from a set of pre-built scenes (Construct 3 template)
  • Hey, guys.

    There's something I'm having trouble with.

    Trying to make a random instance of a ship in a family fire 2 shots of 1 type, then 1 shot of another type, then switch instance.

    I tried it various ways with sub-events where it should have worked and for some reason it doesn't.

    The attached capx is the final version where I fell back on groups as a last resort, but that just made all the ships fire at once.

    http://www.darksunpictures.com/public/A ... _SHOTS.zip

  • You pick a ship but then in the group all ships are picked again, they need to relate to each other, either in the same event as a sub event or send the picked ship through a function as a param.

    I reworked it with a bool that changes for the picked ship, so you can see it act on spacebar press :https://www.dropbox.com/s/mi5xp98xm31fp9s/alternating.capx?dl=0

  • Could you demonstrate? I had it done with sub-events only, based on logic a layman should think would work. The only difference was the Firing Group was a subevent of System -> Every x Seconds (second condition Pick Random Ships Instance), but it wasn't even picking the instance correctly in terms of timing.

  • Yeah I edited a capx probs while you were typing that out, link above xD

  • Thank you, plinkie.

    That works great.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • How would I set a variable fire rate for the same sprite? (without switching instances)

    So Instance 1 of ship X fires at 0.1 (same bullet for all)...

    So Instance 2 of ship X fires at 0.5...

    So Instance 3 of ship X fires at 0.25...

    I thought this would be easy to do, but it's giving me a devil of a time. I mean they all have the same cd or fire rate variable (and you can't set it to random inside the instance variable), so how the heck do you vary it without affecting all? Is there something like pick current or last instance or some equivalent?

  • You can set the instance variable to a random value, it's random(x,y) to pick a random value within a range or choose(x,y,z) to pick one from many.

  • Hey, plinkie.

    Believe it or not I tried a few things, but I was wondering what the best programmer's method would be as all of mine seem bloated.

    For example, I thought I could consistently vary the fire rate for each one of those objects

    http://www.darksunpictures.com/public/SAME INSTANCE FIRE DIFFERENTLY.zip

    by making them separate objects (just same animation) and then you can give them different fire rates, but you'd have to track spawns via an array to make sure they spawn in a pretty unique sequence. That seems a bit bloated.

    You could load up one of those red objects (in capx) with a lot of different fire rate variables and then potentially on spawn set each instance to a unique fire rate? Not sure if that would work, but again seems a bit bloated or not sure if the code would work (I try a lot of different things for hours, but most of them end up not working).

    Without that I thought maybe you could set the fire rate value on spawn, but that just changes it for all the ships.

    Isn't there a nifty programmer way that would make this easy?

    Again, all I'm trying to do is make different instances of the same object fire at consistently different rates I could set.

    I believe this is what you suggested initially, different but consistent fire rates for each ship or ship type (not to put you on the spot or anything).

    I went back to this because the problem with all the other solutions is an inconsistent fire rate based on how many ships have spawned or been killed etc which becomes a bit problematic.

    Plus it becomes boring if all ships of the same type always fire the same, and it looks fake.

    So..... is there a programmer's solution to this?

  • Again, all I'm trying to do is make different instances of the same object fire at consistently different rates I could set.

    Well I've done it here in 2 events. https://www.dropbox.com/s/uwzrvqdh2tlu9 ... .capx?dl=0

    I did it two ways, you can either set the timer wait period to the fire rate, or you can set the speed of the bullet to the fire rate. Both have the same outcome.

    If what you want is for all t1 to fire at the same changing fire rate and all t2 to do the same etc, then you can split out the family event into the 4 types of ship.

  • That is intriguing. And you're right, for all intents and purposes it does look like they have different fire rates, even though there is a slight chance of duplication (about which I don't care).

    The timer is interesting too. Never used, so would've had no idea how to code.

  • yes the duplication can occur as it can pick the same fire rate. The timer, you start counting down when something happens. Then an event 'on timer' activates when the timer finishes.

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