Create object randomly around Player.

0 favourites
  • 8 posts
From the Asset Store
Players follower. use it for anything which follows the player
  • Hi, I want to spawn stars dynamically around the player. So new stars spawn when he moves.

    Problem is... Creating them at player.X/Y + (int(random)) is only going to spawn DOWN and RIGHT.

    I would like to spawn all the way around him.

  • You have to create a formula that allows the randomized number to be negative. I did something similar, like this:

    (For this example, lets say our pixel range we're trying to spawn within is 50.)

    Spawn Object at ((player.X + (int(random(100))) - 50), ((player.Y + (int(random(100))) - 50)

    Since the random number will be between 0 and 100, when it subtracts 50 it gives us a value between -50 and 50. Hope this helps!

  • whiteheat

    random(-50,50) works too.

    spawn object at player.x+random(-50,50), player.y+random(-50,50)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hahaha, it seems this is how my forum posts always go: I post some kludged-together method I busted my butt figuring out, and then some more skilled and experienced user shows me a simpler, more efficient way to do the same thing :D

    Thanks keepee, it's how I learn!

  • whiteheat

    haha yep, i know the feeling..!

  • Thanks you two ^^

    I think I go with the simple one for now :P

    Although I don't quite get it.

    First it randoms 0 to -50 and then 0 to 50 and finds a number in between those?

  • Nope, it just returns a random number in between the two values.

    and if you only put one number in like random(5) it will interpret that like random(0,5)

  • That makes sense duh ^^ Just like normal.

    Well that solves that question for now.

    I still have to find a way to create 500 pixels away from the player ^^ That is gonna get a bit tricky Heh.

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