Alternating Shots/Random Instance [C2] [SOLVED]

Just started using Construct 2? Post your questions here

Post » Tue Jul 25, 2017 7:29 pm

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
Last edited by AmpedRobot on Wed Jul 26, 2017 12:41 am, edited 1 time in total.
B
39
S
20
G
18
Posts: 265
Reputation: 12,983

Post » Wed Jul 26, 2017 12:21 am

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
B
47
S
17
G
81
Posts: 2,223
Reputation: 48,093

Post » Wed Jul 26, 2017 12:26 am

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.
B
39
S
20
G
18
Posts: 265
Reputation: 12,983

Post » Wed Jul 26, 2017 12:26 am

Yeah I edited a capx probs while you were typing that out, link above xD
B
47
S
17
G
81
Posts: 2,223
Reputation: 48,093


Post » Fri Jul 28, 2017 2:29 am

@plinkie

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?
B
39
S
20
G
18
Posts: 265
Reputation: 12,983

Post » Fri Jul 28, 2017 3:43 pm

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.
B
47
S
17
G
81
Posts: 2,223
Reputation: 48,093

Post » Fri Jul 28, 2017 9:55 pm

Hey, plinkie.

@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?
B
39
S
20
G
18
Posts: 265
Reputation: 12,983

Post » Sat Jul 29, 2017 12:55 am

AmpedRobot wrote:
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.
B
47
S
17
G
81
Posts: 2,223
Reputation: 48,093

Post » Sat Jul 29, 2017 4:50 pm

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.
B
39
S
20
G
18
Posts: 265
Reputation: 12,983

Next

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 0 guests