# Random Enemy Spawn

ðŸ‘‰ BlitzCoder will be building a new platform and other plans to preserve and continue the Blitz legacy.

To be able to achieve this goal, we need your support by becoming a Patreon Paid Member ðŸ‘ˆ

Tweet 3d

How to make enemy randomly spawn, please tell me.

Lookup Rand command for integer and Rnd for float, use those for random x,y,z positions. The high and low value is for range.

For random time, you can set a minimum time (re)spawn, say at least 30 seconds and then put a random high value range. Rand(30,60) //between 30 to 60 seconds

The Millisecs() example also shows how to setup a timer for executing conditional code.

pair it with SeedRnd Millisecs() at your start of your code for better random results.

RonTek, ik im 2 months late, but can you send me an example code please.

thanks
-Loud64

It will help you better if you know the logic.. it's actually pretty simple:

1. Create a timer that counts 0 - 60 every time in your main loop. use CurrentTime\$ and get the seconds part just for starters.
2. Pick a random second using the command I posted above
3. Spawn the enemy when that second passed.
4. Repeat step 1 for the next random spawn.

Pick a minimum spawn time say 10 seconds so it's far apart for the next random spawn.. Rand(10,60)

RonTek, Can you check out my name game "The Curse Of The LightHouse" On YouTube?

EntityTexture emd2,emtex2
ScaleEntity emd2,0.005,0.005,0.005

Type grunt
Field entity, tobedeleted
Field gx#
Field gy#
Field gz#
End Type

For zit =1 To 15
s.grunt = New grunt
s\entity=CopyEntity(emd2)

gx#=Rand(25,10);25,100
gy#=35
gz#=Rand(50,110); 50,110
PositionEntity s\entity,gx#,gy#+64,gz#
PositionEntity s\entity,Rnd(150,120),35,Rnd(70,150):TurnEntity s\entity,0,Rnd(40,180),0
AnimateMD2 s\entity,1,0.05,1,15:UpdateWorld
EntityType s\entity,2;changed from 1 to avoid collisions
Next
SeedRnd (MilliSecs())
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Use something similar to this

@Doggie, your demonstration helped me understand types better than any of the documentation or tutorials haha, maybe now I can finally get my health packs working properly!