Pick A Random Family [C2] [SOLVED]

Just started using Construct 2? Post your questions here

Post » Tue Jul 11, 2017 4:34 pm

Hey, guys.

Been a while.

I had the perfect code for shot spawning in the prototype (just system every few seconds create object), which worked flawlessly when **picking a random instance of the SAME sprite.**

I upgraded the game to cohorts of ships. Yes, cohorts! Basically there a lot of different sprites now and picking a random instance of a sprite out of many of these doesn't work the same. I tried replicating the original look and frequency of shot spawning, but it doesn't work the same (looks awkward), shots don't spawn enough or too frequently, so I guess I have to do this the right way.

Question is how?

One way I'm thinking would be to track the different ships (sprites) which have spawned, which are actually visible on screen, in the player window, but no idea how to do this. Guessing maybe tracking them somehow w UID, but I've never done the code and might take me a long time to work out.

So once you have them tracked, treat that group as if it were one sprite for the frequency of shot spawning (pick a random instance for shot spawning out of that group of many different sprites), then the same frequency I had originally for shot spawning should work.

I realize this is a lot to ask for and might be pretty advanced.

Anyone care to take a gander at this?
Last edited by AmpedRobot on Fri Jul 21, 2017 6:32 pm, edited 1 time in total.
B
41
S
20
G
18
Posts: 274
Reputation: 13,055

Post » Tue Jul 11, 2017 4:45 pm

This is really confusing, what do you mean by shot spawning and picking a random instance of that sprite? Are you talking about firing bullets at ships and picking a ship to fire at? What is the game?
B
47
S
18
G
84
Posts: 2,273
Reputation: 49,800

Post » Tue Jul 11, 2017 4:51 pm

Sure man.

Well, basically I had just 1 place holder enemy ship in the prototype.

Very simple code for the ships firing bullets.

Every x seconds, pick a random instance of that sprite and create an object/sprite (bullet).

-----

Now, it isn't just one enemy ship.

I have many different types of enemy ships.

I want to replicate the original frequency/look of bullet spawning.

----
If I do the same code for each different enemy ship sprite now, the frequency of bullet/shot spawning is way off because it picks a random instance of a sub-group (not the group of many different sprites).

every x seconds, pick a random instance of Sprite A, and create bullet.

every x seconds, pick a random instance of Sprite B, and create bullet.

If you introduce just 1 extra sprite enemy ship sprite, the frequency of bullet spawning is completely different vs:

every x seconds, pick a random instance of Sprite A, and create bullet.
B
41
S
20
G
18
Posts: 274
Reputation: 13,055

Post » Tue Jul 11, 2017 5:01 pm

One more thing.

You might think this would be easy to do by just setting a frequency for each different sprite.

Well, it gets complicated because for now I'm spawning x different random types of starships and the ships which are visible on screen vary.

So if you have a code every x seconds and your particular ships are not visible on screen/spawned, you either have ships firing too much or too little.
B
41
S
20
G
18
Posts: 274
Reputation: 13,055

Post » Tue Jul 11, 2017 5:02 pm

Use a Family.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue Jul 11, 2017 5:05 pm

I did actually.

It was the first thing I tried, but it didn't work. It made all ships fire simultaneously all the time.

Unless something went corrupt.

Maybe I should try this on a simple fresh capx if this does actually work?
B
41
S
20
G
18
Posts: 274
Reputation: 13,055

Post » Tue Jul 11, 2017 5:29 pm

Instead of using every x seconds can you give each ship on created its own variable which is the shooting speed and use this? Does the shooting speed alter for each individual ship during the game? I can't tell if you're trying to mimic randomness with every X seconds or if there's a reason behind it.
B
47
S
18
G
84
Posts: 2,273
Reputation: 49,800

Post » Tue Jul 11, 2017 6:03 pm

Well, the problem with instance variables in this instance is that it would make every spawned instance of the same ship type fire at the exact same frequency? Which would look pretty fake? Not sure if you can introduce some randomness into instance variables (yet another suggestion idea for C3).

I still have to make a simple capx for the family tests. That might actually work. Or maybe not. Who knows.

(I would also recommend sequential saves for all your C2/C3 work, as it greatly reduces the chance of corruption, similar like they have in 3dsMax and Autodesk Maya. It's something they don't teach nebes, but it's really important.

Someone will save into the same file for 3 years and then it goes kablooey! And they're surprised why. It must be the software. I only learned that in class because you can't Google/You Tube what you don't know :P )
B
41
S
20
G
18
Posts: 274
Reputation: 13,055

Post » Tue Jul 11, 2017 6:26 pm

plinkie wrote:Instead of using every x seconds can you give each ship on created its own variable which is the shooting speed and use this? Does the shooting speed alter for each individual ship during the game? I can't tell if you're trying to mimic randomness with every X seconds or if there's a reason behind it.


Let me add an addendum.

I think this is actually a really good idea.

Just realized I could do a random roller for several different instance variables.
B
41
S
20
G
18
Posts: 274
Reputation: 13,055

Post » Tue Jul 11, 2017 6:27 pm

You can definitely do what you are trying to achieve, I'm just trying to get to the bottom of it lols. When you spawn the ship, of any type, you can set the shootspeed instance var to random(10,20) which would be a random value 10-20, and different for each ship. There are various ways to do this. You can do this with a family instance variable if it applies to every ship. If it's different speeds for different types you can say on Type A created, set instance var to random (10,20), Type B to random(60,80). This is how I would do it myself but there are many ways.
B
47
S
18
G
84
Posts: 2,273
Reputation: 49,800

Next

Return to Beginner's Questions

Who is online

Users browsing this forum: No registered users and 4 guests