How do I spawn on borders.

0 favourites
  • I only want my objects spawning on my outside borders. (25x, 475x, 25y, 475y) but i want it to be anywhere on the outside

    X25 Y0-500

    X475 Y0-500

    X0-500 Y25

    X0-500 Y475

    I want it to spawn at a random place there every 1 second. How would I do that?

  • the main method is

    Spawn Object at ->

    x: 25 - sprite.width

    y: random(0,500)

    puts the sprite to the left of your left boundary.

    copy/alter code for the other 3 boundaries.

    then, to trigger it

    every 1 sec, round(random(0,3) [choose which side to spawn on]

    if 0 then

    Spawn Object at ->

    x: 25 - sprite.width

    y: random(0,500)

    if 1....

    so on and so on

  • I tried this but now it only seems to be spawning on half of each side.

    (spawn rate multiplied by 250 to demonstrate where spawning isnt happening)

  • try changing the random variables to

    floor(random(0,3)

    the other option would be to just spawn anywhere on the map

    Add a box sprite over earth to create your non-spawning zone

    on object created, if overlapping no-spawn zone sprite, then teleport the sprite elsewhere

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • try changing the random variables to

    floor(random(0,3)

    the other option would be to just spawn anywhere on the map

    Add a box sprite over earth to create your non-spawning zone

    on object created, if overlapping no-spawn zone sprite, then teleport the sprite elsewhere

    Ah. I see how you got confused here (as the diagram shows spawned objects that have already moved). I only want it spawning on the sides and then moving towards the center (which is working but as you can see half of each side has no spawn for some reason).

  • Could you upload the file.

  • Here

  • One problem here is that that function doesn't actually equally distribute numbers between 0 and 3. 0 and 3 are actually half as likely to be chosen as 1 and 2 (for example 0 gets chose if random gives numbers between 0 - 0.499.., 1 gets chosen between 0.5 - 1.499.. (twice the probability). If you want equal distribution you could change it to for example int(random(0,3.99).

    It would be easier to get a closer look if you upload the project thou.

  • Yes,

    Change it to

    Random(0,10)

    Then

    0-2.5

    2.5-5

    5-7.5

    7.5-10

    For a better distribution

    Or even 0 to 100

  • I think int(random(0,3.99) is just fine. Or if you want to be really OCD about it change it to int(random(0,3.99999...) :) The "distribution" doesn't really become any more accurate if you use a bigger spread like 0 - 100.

    Anyhow, here is an example file how to do it.

    dropbox.com/s/7xn4k2w2ljk51me/RandomSpawnAtEdge.c3p

  • Or maybe it would look better to spawn them around the object in a circle?

    Here's an improved example:

    dropbox.com/s/no7thxdeha71bys/RandomSpawnAtEdges2.c3p

  • Would it work better with

    Random(-0.5, 3.5?)

  • Or maybe it would look better to spawn them around the object in a circle?

    Here's an improved example:

    https://www.dropbox.com/s/no7thxdeha71bys/RandomSpawnAtEdges2.c3p?dl=0

    Do you have a way I can message you thats a bit easier? Instagram? Discord?

  • I can probably currently answer you best here :)

    Actually you would have to do it round(random(-0.49, 3.49)), but I think my way is more intuitive. Check out the example I uploaded.

  • I can probably currently answer you best here :)

    Actually you would have to do it round(random(-0.49, 3.49)), but I think my way is more intuitive. Check out the example I uploaded.

    I checked out your example and it seems pretty cool. Also the first one works better as I want it spawning at the edges

    ill test it out soon

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