#I need help implementing a randomly weighted spawning system

1 messages · Page 1 of 1 (latest)

late mason
#

So for the longest I've been struggling on this (more like procrastinating) and I've finally decided to give in.

What I need (or I think I do) is so when the weighted rng finishes randomizing, it puts the output of which ball it should spawn in the inst().

#

If needed it I will gladly provide more context

steady shale
#

Hello! What are you trying to achieve with this code?

Code looks fine I guess, you want to print the position of the ball that was spawned? Or to print the "ball number" that was spawned?

late mason
gentle drift
#

Well right now you only have one ball so I don't even know how you plan to proceed

#

You need, at the very least, an Array of PackedScenes with different balls

hoary tapir
#

IF you're instantiating different balls with different properties this should be fine, you'd just call the init function with the position

But you want the positions to be randomly placed?

Essentially you'll need to just write an x,y rng so have a minX maxX minY maxY and then randomize inside of that and add any weighting you need

#

plus you could add colliders to them so that they space themselves out a bit if too close on spawn?

gentle drift
#

Well he said "which ball" implying different balls
Also randi_range(0,0) is 0 at all times, you can replace that with 0

late mason
#

sorry

#

should've been more specific

late mason
gentle drift
# late mason I have 3

Okay well you need to create an Array of PackedScene to hold them all, then use rand_weighted() to draw an index