Topic was automatically imported from the old Question2Answer platform.
Asked By
Robster
Old Version
Published before Godot 3 was released.
Hi all,
I want to randomly generate some powerups as my game objects are loaded (bricks in Breakout).
I was thinking something like:
var randomNumber = randi()%101+1
if randomNumber == 1:
#then we have a 1 in 100 chance of being picked
#do stuff here
Can anyone give feedback on the code?
The idea is I want to have different chances of a specific powerup being chosen. So something like:
if powerup == "speedBall":
#make speedball a 1 in 100 chance of being drawn
var randomNumber = randi()%101+1
if randomNumber == 1:
#then we have a 1 in 100 chance of being picked
#do stuff here
elif powerup == "growBat":
#make growBat a 1 in 40 chance of being drawn
var randomNumber = randi()%41+1
if randomNumber == 1:
#then we have a 1 in 40 chance of being picked
#do stuff here
I’m happy to progress with this idea but wanted to check in, see if anyone can see any issues etc or some better suggestion?
Give each powerup a chance, the level or difficulty manager may need to modify it too according some rules.
The powerup picker gets one up from the sum of chances (and possible modifiers), the manager decides which powerup fall in that number.
Expanding a bit the idea:
Chances.
PowerupA: 40
PowerupB: 60
PowerupC: 20
|.......... ................. .......
| | | |
| A | B | C |
| | | |
+-------------------------------------->
The picker gets a number from 120, the manager decides which one falls there, this could be dynamic so if you keep adding powerups, the system won’t need to be touched.
This could allow to set fuzzy logic rules, near of where the vertical lines are, you could add overlapped chances for one or another, is something common for AI but useful for subtle difficulty settings and scaling too (is just a bit harder to design).