Topic was automatically imported from the old Question2Answer platform.
Asked By
Lapsyy
Hi, in my game i have an enemy spawner which has three types of enemies, i want two of them to have equal 40% chance while the other has only 10% chance of spawning, how do i do this?
Assuming you did your math correctly and want nothing to happen 10% of the time, you would use:
var chance = rand_range(0, 100)
if chance < 40:
spawn(1)
elif chance < 80:
spawn(2)
elif chance < 90:
spawn(3)
else:
pass # Do something else?
If you do want to always spawn enemies, you should recheck your numbers (they should add up to 100%) and use similar logic at the appropriate break points.