Random Function (for spawn locations and random spawnings)

KamazarKamazar Member Posts: 287
edited November -1 in Working with GS (Mac)
Got yet another question, is there a random function somewhere? I'm trying to do two things.

1) Be able to create random locations for the enemy to spawn off-screen (kinda interferes with destroying my enemies once they leave the screen, but I'll try to fix that later), but are somehow not too far away from their target. If I create actors that spawn for me, it makes the game predictable, which breaks down what I'm trying to do.

2) Make the spawn times random. I don't want a steady stream, otherwise there'd be a flood of enemies from nearly every direction.

These both need a random function, and the Timer behavior doesn't even have a formula line. If this can somehow be found out, I'm even willing to write a Wiki for it. This is crucial for several types of games.

I tried creating some x>x game attributes to use with actors, but none of the settings support them.

Comments

  • KamazarKamazar Member Posts: 287
    Haha, maybe I should've done more than skim the wikis. Thx, CodeMonkey.

    Alright, I have another question/problem. I set the spawn instruction so that the location of said spawning would occurs between or equal to the X points 320 and 420 and Y points 0 and 480. In other words, the spawning occurs above the screen. Now, my question is, every time there's a spawn, is a new number (for the X and Y coordinates) generated, or are the same coordinates used? Cuz I keep getting enemies coming in from the same location, which obviously is a problem. Has anybody that's done random spawns before help me out on this one?
  • JGary321JGary321 Member Posts: 1,246
    I have, they spawn randomly each time. Every time a spawn occurs, it randomly selects a new location the next time within your coords.
  • quantumsheepquantumsheep Member Posts: 8,188
    I use a game controller (invisible actor that you can chuck some commands into to 'control' the level).

    In this actor, I use a timer, so that every 2 seconds, it spawns an enemy at a random location.

    Then every 7 seconds, it spawns a different enemy at random coords.

    I think because the random function is called with the timer it comes up with a new set of coords ever time. Seems to work ok - you can see it in effect in my Sol demo here: http://gamesalad.com/game/play/4569

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • KamazarKamazar Member Posts: 287
    Yep, got it to work. Don't know what went wrong, but after some tinkering, it's random. It's weird, though. I set it up so that all spawning would come from the top. Now they come from all directions (not that this is the problem, this was my main goal). I'll try to look into it. Maybe it has to with the wrapping...

    And yeah, I use a controller to. Oughta be the first trick a rookie learns. Keeps everything a little more organized ;) The timer's currently set for every 5 seconds, so if your theory's true, I shouldn't have a problem. Nice demo, BTW. Really like the cross hairs.

    So, yeah... thx, JG and QS. Hopefully I won't have anymore questions 'til I get my first playable demo up and running.
  • quantumsheepquantumsheep Member Posts: 8,188
    Looking forward to it mate ;)

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

Sign In or Register to comment.