Spawn actors at random times without them eventually spawning at the same time

CraigMackCraigMack Member Posts: 27
edited January 2015 in Working with GS (Mac)

I am creating a car game where the main car (You) needs to avoid cars that are coming down the road, and to do this you need to switch lanes. The main problem I have is spawning in the Enemy cars that are coming down. I am wrapping Y

I used this timer that would spawn in the actors at random times but the actors eventually ended up spawning at the exact same time and i lost the game because i couldn't go to any free lane.

It would help if someone could help me with the code, and provide a spawner that would spawn cars at set positions at completely different times and they never spawn at the same time.

Best Answer

  • tatiangtatiang Posts: 11,949
    Accepted Answer

    My demo is a bit more complicated than what you just posted, which has some basic errors (random values from 1 to 7 cannot equal 8; having a rule with All conditions selected instead of Any and conditions that can't be true at the same time means that the rule will never fire; etc.) but hopefully you find it useful.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Answers

  • Simple AppsSimple Apps Member Posts: 158

    I think you can use only one actor to spawn enemies down.
    and make the spawner to move left and right.
    and spawn at random timings. i hope you understand.

  • CraigMackCraigMack Member Posts: 27

    Do you know how i would do that? and im not quite sure what you mean

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    I recommend not wrapping Y and just spawning cars randomly.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • Simple AppsSimple Apps Member Posts: 158
    edited January 2015

    make self attribute (start X )for the Spawner

    1st rule:

    change attribute (start X) to (self position x)

    2nd rule:

    interpolate

    when self position x = self start x

    interpolate self position x to selfstart x -200

    3rd rule

    interpolate

    when self position x = self start x-200

    interpolate self position x to selfstart x

  • CraigMackCraigMack Member Posts: 27

    Yes i understand what you mean but my game is kind of like the game on the app store 2 cars by ketchapp if you guys have it. I need to avoid the cars that spawn at the top of the screen by moving left or right but the problem i have with this is that all the cars i have set up to spawn eventually spawn at the same time and there is nothing i can do.

  • Simple AppsSimple Apps Member Posts: 158

    You take two spawnners
    one move left and right between 1 to 100
    and another move left and right between 100 to 200
    so that the enemies don't spawn at the same time

  • CraigMackCraigMack Member Posts: 27

    This is a picture of the sort of game i am trying to create. I understand what you are saying but i need the cars to come down the Y axis and the main actor just to stay in the same spot and move left and right

    http://prntscr.com/5pnyrd

  • CraigMackCraigMack Member Posts: 27

    ive got the actor moving and the walls set up its just the enemy actor bit and the spawning which i am struggling with

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited January 2015

    You rejected my answer so I'm trying to understand what you need. Do you need the car actors to wrap? I've never played 2 Cars but it looks like the shapes don't actually wrap in that game:

    What might help is to have a description of how you want the cars to spawn. For example, do you want only one (randomly chosen from four choices) car to spawn at a time? Or do you want up to four cars to spawn in four separate lanes? In the image you posted (http://prntscr.com/5pnyrd), it shows two cars spawning at the same time in different lanes. Is this okay?

    Lastly, what actual rules have you tried so far for spawning?

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • CraigMackCraigMack Member Posts: 27

    As you can see in that video the shapes spawn in at the top and move down i am trying to do the same concept but with cars. My problem is ive searched on youtube and the forums and all of the spawning methods i have tried the cars eventually spawn at the exact same time (all cars spawn in a row) and the main character has nowhere to go apart from losing.

  • CraigMackCraigMack Member Posts: 27

    I want to spawn a car randomly from four or more choices so the player has more options on where to go

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited January 2015

    I see what you're saying. I have a demo that shows how to do this but you'll need to figure out how to modify it so that it's not always 3 of 4 cars.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • CraigMackCraigMack Member Posts: 27
    edited January 2015

    This was the first behaviour i tried from looking at a youtube video but it was not what i was looking for

    http://prntscr.com/5poca0

  • CraigMackCraigMack Member Posts: 27

    Yeah thanks

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    You asked about spawning 5 actors. To do so you would add two more spawn actor behaviors which would also require two more table rows. The random number in the demo chooses a row NOT to spawn. So currently, it chooses 1 of 4 rows but you could change that to 1 of 6 for example to spawn 5 of 6 possible positions.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

Sign In or Register to comment.