Random object spawn, but not near player

Get help using Construct 2

Post » Wed Sep 25, 2013 5:31 pm

So i've made my first little zombie-like game, but i seem to have a problem.

What now happens is as soon as you kill a zombie, there spawns another one randomly at the map. But it can also spawn like 1 pixel away from the player, the player will be dead in no time like this.

Does anybody know how to spawn an object random at the map but not near another object?

Sorry if this is a noob quuestion, new to this (:

In advance, Tnx!
B
4
Posts: 14
Reputation: 228

Post » Wed Sep 25, 2013 5:33 pm

Just noticed this is the wrong part of the forum, sorry for that.
B
4
Posts: 14
Reputation: 228

Post » Thu Sep 26, 2013 11:29 am

you can create a loop which generate two random numbers X and Y until those coordinates are far enough from the player position (say 100 pixels). You can use the distance() expression for that. Unless your layout is very small, chances are that loop won't need to execute too many times until the exit condition is met.

Edit: when generating the random numbers, you must specify limits which correspond to your layout size.OlivierC2013-09-26 11:38:04
B
12
S
5
G
2
Posts: 132
Reputation: 2,627

Post » Sat Sep 28, 2013 10:22 am

Another way is create the item once an move it if is too close to the char, for instance let's say something like add 200*random(0.5,2)

This way u will move the item 100-400 pixels from your char

Hope it helps



B
7
S
2
Posts: 16
Reputation: 1,107


Return to How do I....?

Who is online

Users browsing this forum: Euduardo, Kin and 36 guests