GameSalad

Weighted Random selection with dynamic adjustment with just 8 behaviors.

HopscotchHopscotch Posts: 2,551Member, PRO

What is it good for?

Imagine you want waves of enemies, randomly spawned ...

... but you would like to start with more of the easy monsters in the beginning,
then as the level progresses, increase the frequency of tougher enemies.

Or simply define the type and frequency of enemies per level.

(Project attached)

Comments

  • SocksSocks London, UK.Posts: 12,437Member
    edited May 11

    Amazing stuff !! Thanks for sharing !! :)

    P.S love the interface too !!!

  • ArmellineArmelline Posts: 4,354Member, PRO

    Love it! Can't wait to take some time to dig in to exactly how it works!

  • gingagaminggingagaming FREELANCE GS DEV Posts: 1,405Member, PRO

    Great work Roland!

  • Braydon_SFXBraydon_SFX Dallas, TexasPosts: 8,783Member, Sous Chef, PRO, Bowlboy Sidekick

    Very cool and very handy! Thank you so much for sharing!

  • RThurmanRThurman Posts: 2,688Member, Sous Chef, PRO

    This is great! Thanks for sharing with the community!

  • HopscotchHopscotch Posts: 2,551Member, PRO

    Thanks for the comments @Socks, @Armelline, @gingagaming, @Braydon_SFX, @RThurman !

    @Armelline said:
    Can't wait to take some time to dig in to exactly how it works!

    After messing about, the simplicity surprised me:

    Make a table with enemies, adding the desired ratio each should appear. The order does not matter.

    Now pick a random value from the sum of the ratios.

    Then loop over the enemy table, subtracting each ratio from your random number until you reach 0 or less. The previous enemy is then the one to spawn.

  • SocksSocks London, UK.Posts: 12,437Member

    @Hopscotch said:
    After messing about, the simplicity surprised me:

    Things are always 'simple' once you've worked out the answer.

    @Hopscotch said:
    Now pick a random value from the sum of the ratios.

    Then loop over the enemy table, subtracting each ratio from your random number until you reach 0 or less. The previous enemy is then the one to spawn.

    Oh yeah, that was really obvious, I'm surprised you even had to work it out :p :)

  • PhilipCCPhilipCC Encounter Bay, South AustraliaPosts: 1,171Member, PRO

    @Hopscotch Snippets of brilliance like this inspire me with some great ideas that I would never attempt on my own without your tutelage. Once again, thank you. :)

  • HopscotchHopscotch Posts: 2,551Member, PRO

    @Socks :D Well, yeah, things always get lost in translation somewhere between my brain and mouth, I blame it on a sinus condition.

    My pleasure @PhilipCC :)

Sign In or Register to comment.