playMaker

Author Topic: Looking for a more elegant way to set weighted values on the fly  (Read 188 times)

krmko

  • Hero Member
  • *****
  • Posts: 629
    • View Profile
    • Fat Pug Studio
Looking for a more elegant way to set weighted values on the fly
« on: February 14, 2018, 06:47:48 AM »
Hi guys,

i have a system with weapon upgrades in the game where the equipped weapon gets upgraded if you pick up the same weapon again.

I want to make the possibility of spawning the same weapon from the pickup a bit higher, so, for example, if i have a sword equipped and there's a loot box, which can contain one item of 10 random items (10% chance for every weapon) and i ramp up the weight for sword by 20%, there will be 30% possibility to spawn a sword and 7,77% possibility of spawning something else.

I have a bit inefficient system, so i'd like some ideas how to improve it. Currently, i get the name of the equipped weapon and do 20 string switches. When i get a match, i raise the matched weapon's weight a bit. The thing is, i also need to lower the other weapons' weights and then reset everything after the spawn, which is tedious.

Also, i don't quite get the concept of weighted index, if one item weight is 0.6, and other is 0.8, which is 1.4 altogether, what is the actual chance of those being selected? Should i have a 0.05 weight for every item if i want 5% chance of spawning it? And what when i put a new item, do i have to recalculate the weight for all items again?
« Last Edit: March 08, 2018, 05:39:49 AM by krmko »

krmko

  • Hero Member
  • *****
  • Posts: 629
    • View Profile
    • Fat Pug Studio
Re: Looking for a more elegant way to set weighted values on the fly
« Reply #1 on: February 14, 2018, 08:55:08 AM »
Hmm, i just figured out that i can put the logic on the weapon itself to add weight to the element in pickup weight float hash table when it is equipped, but still the problem of manually reducing the chance for all other weapons remain.

krmko

  • Hero Member
  • *****
  • Posts: 629
    • View Profile
    • Fat Pug Studio
Re: Looking for a more elegant way to set weighted values on the fly
« Reply #2 on: March 08, 2018, 06:13:33 AM »
Hm, i need help on this one. More here! > http://hutonggames.com/playmakerforum/index.php?topic=18447.0