Best way to randomly spawn actors from off screen?

justinodunnjustinodunn Member, PRO Posts: 226

So these actors (obstacles) being spawned are programmed to move towards the center of the screen. Currently I have 4 spawners to spawn the actors from the left, right, top and bottom positions. Each with a random timer set between 1 and 5 seconds.

The thing I'm worried about is the timing. If actors from spawners at each side somehow spawn at the same time and move into the center close together, this might make it impossible for the main actor to dodge these obstacles. Any ideas how I can go around this? Thanks.

Comments

  • johnnymagnejohnnymagne NorwayMember Posts: 112

    Set up 4 timer attributes and use a rule for each spawner that excludes (and pulls a new random value) if same value as on the three other timer attributes (use integers). Quite brute but should work.

  • justinodunnjustinodunn Member, PRO Posts: 226

    @johnnymagne said:
    Set up 4 timer attributes and use a rule for each spawner that excludes (and pulls a new random value) if same value as on the three other timer attributes (use integers). Quite brute but should work.

    Thanks for the reply. Is it possible to have 1 or maybe 2 spawners for spawning enemies from all 4 directions?

  • johnnymagnejohnnymagne NorwayMember Posts: 112

    Yes. But check out this thread, you'll find what you need to proceed:
    http://forums.gamesalad.com/discussion/68841/random-numbers-no-repeating

  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2016

    @justinodunn said:
    Is it possible to have 1 or maybe 2 spawners for spawning enemies from all 4 directions?

    These numbers (512 and 384) are for a landscape iPad project size, change them as needed.

    Every X seconds . .
    --Change A to A+(random(1,3)*90)
    --Spawn • relative to Scene • X: 512*cos(A)+512 • Y: 384*sin(A)+384

    If the goal is not to have two or more obstacles arrive at the centre of the scene at the same time then (seeing as you will be working with a 4:3, 3:4, 16:9 or 9:16 scene) you will need to account for the difference in distance from the edge of the scene to the centre between the longer and shorter sides.

    For example - imagine a landscape 16:9 scene - you could spawn an obstacle from the left hand edge, moving at X/pps, then a second after that spawn an obstacle from the top edge, moving at the same speed, and they can arrive at the centre of the scene at the same time as the one spawned from the top edge has less distance to travel.

    If you want your obstacles to always move the same rate then the easiest way would be to spawn them at the same distance, so the top and bottom edge obstacles should be spawned further off screen at the same distance as the left and right edge obstacles.

    Otherwise you could make the obstacles spawned at the top and bottom edges move slower (56.25% of the left and right edge obstacle speed).

  • justinodunnjustinodunn Member, PRO Posts: 226
    edited December 2016

    Thanks for the help Socks, to address your problem about left and right sides being different distances to the top and bottom, I've decided to take out the left and right spawning.

    So currently I have 3 spawners, 2 are spawners for both top and bottom and the third spawner spawns a obstacles on either bottom or top sides. All three actors that are being spawned from these spawners are programmed to move towards the centre.

    Is it possible to just make it so they don't spawn at the same location? right now they're spawned at a random x location between 0 and 320

    Johnny I apologize but I don't see how the formula in that link can be applied to multiple spawners, could you please elaborate?

Sign In or Register to comment.