Random object spawn, but not near player

0 favourites
  • 4 posts
From the Asset Store
Players follower. use it for anything which follows the player
  • 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!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Just noticed this is the wrong part of the forum, sorry for that.

  • 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.

  • 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 <img src="smileys/smiley2.gif" border="0" align="middle">

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)