#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Spawn Randomly

Posts: 4Member

Hi.

So I want to make a game where there is an element to spawn powerups. I am using the position of the player to spawn the different powerups, but I want it to spawn randomly, like you don't even know what is going to spawn next. How do I do it? I appreciate your help.

• Posts: 450Member

I can't remember if the spawn behaviour allows attributes yet and don't have GS on this machine. If it does, you only need the first half of this. If it doesn't a quick and dirty way of doing it would be the following.

Let's say you have 10 powerups.

Create a new attribute called random_powerup.

Then change the attribute to random(1,10)

Then use this attribute to spawn your powerups. Create a series of rules that say:

if random_powerup = 1, spawn powerup1
if random_powerup =2, spawn powerup2

etc

• Posts: 4Member
edited May 2016

@imjustmike said:
Create a new attribute called random_powerup.

Is the attribute a game attribute, scene attribute, or actor attribute? Thanks

• Posts: 1,478Member, PRO

@yoaprz actor attribute

• Posts: 4Member

@Icebox said:
@yoaprz actor attribute

@Icebox Thanks a lot!

@imjustmike said:
I can't remember if the spawn behaviour allows attributes yet and don't have GS on this machine. If it does, you only need the first half of this. If it doesn't a quick and dirty way of doing it would be the following.

Let's say you have 10 powerups.

Create a new attribute called random_powerup.

Then change the attribute to random(1,10)

Then use this attribute to spawn your powerups. Create a series of rules that say:

if random_powerup = 1, spawn powerup1
if random_powerup =2, spawn powerup2

etc

@imjustmike So if I want the chances to appear be different for each powerup, i just make more numbers for a certain powerup? Thanks.

• Posts: 450Member

@yoaprz said:
@imjustmike So if I want the chances to appear be different for each powerup, i just make more numbers for a certain powerup? Thanks.

That's an easy way of doing it, yeah. If you want powerup1 to be twice as common as powerup2 you could have a rule that says

if random_powerup = 1 or 2, spawn powerup1
if random_powerup =3, spawn powerup2