Pick A Random Family [C2] [SOLVED]

0 favourites
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • 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?

  • 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?

  • 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.

  • 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.

  • Use a Family.

  • 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?

  • 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.

  • 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 )

  • 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.

  • 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.

  • >

    > Just realized I could do a random roller for several different instance variables.

    >

    Yep looks like you've got it now.

  • Would there be a way of grouping many different sprites on screen for comparison purposes?

    I just discovered the "pick all instances" and "is on screen".

    So how to use that for say 5 different ship/sprite types on screen and then pick a random instance out of all that?

    Is that possible?

  • Assuming they are still in a family, pick random family instance, family is on screen.

  • Ok, lemme test.

    That would simplify my life quite a bit.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Dude, read your PM's from dayssssssssss ago. Example in there.

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