Spawning random actors

umeiumei Member, PRO Posts: 21
I am looking to spawn random obstacles in my game. My obstacles are spawned every 2 seconds so I made an attribute 'random obstacle' and changed attribute to random(1,3) in a timer.

Here is how my controller actor is set up:

http://imgur.com/hXr2FKg

Then in my goal actor I am have 3 rules for each obstacle like below:

http://imgur.com/Nu0qsBQ

The random obstacles spawn correctly but they spawn on top of each other. I can not figure out what I am doing wrong.

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    You are spawning actors at position 0,0 relative to actor (the spawning actor). So they are all on top of each other.

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

  • umeiumei Member, PRO Posts: 21
    I should change it relative to scene?
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Do you want the actors all to spawn at x=0, y=0? Because that's what will happen if you change it to relative to scene. The question is, where do you want them to spawn?

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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I can't see the whole expression that includes self.gap (is this a flappy bird game???) but whatever that is set to is affecting where your obstacle actors are spawning. Your goal actor will spawn on top of the actor that spawns it.

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

  • umeiumei Member, PRO Posts: 21
    Here are all the rules http://imgur.com/Snh9ElZ
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Okay, thanks. Add a Log Debugging Statement before each spawn actor behavior in your rules and change the expression to self.gap. Then open the Debugger and watch to see the values of self.gap. What do you notice?

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

  • umeiumei Member, PRO Posts: 21
    Log(Actor: goal ): 229
    Log(Actor: goal ): 229
    Log(Actor: goal ): 229
    Log(Actor: goal ): 94
    Log(Actor: goal ): 94
    Log(Actor: goal ): 94
    Log(Actor: goal ): 228
    Log(Actor: goal ): 228
    Log(Actor: goal ): 228
    Log(Actor: goal ): 128
    Log(Actor: goal ): 128
    Log(Actor: goal ): 128
    Log(Actor: goal ): 183
    Log(Actor: goal ): 183
    Log(Actor: goal ): 183
    Log(Actor: goal ): 249
    Log(Actor: goal ): 249
    Log(Actor: goal ): 249
    Log(Actor: goal ): 118
    Log(Actor: goal ): 118
    Log(Actor: goal ): 118
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2014
    Well, those values are obviously in a range so that wouldn't explain the problem you're seeing. Any chance you can .zip the project file, upload it to a file-sharing service, and then send me a link (or post it here)? If you send me a private message, it's helpful if you reference this thread by URL: http://forums.gamesalad.com/discussion/65132/spawning-random-actors.

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

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    Thanks for sending the file. What should I be looking for? Which actors are the ones that you're seeing spawning on top of each other and at what point in the game?

    Also, one thing to note is that if you have an integer attribute and you set it to a value such as random(1,3) and then you have a rule when game.random=1... you don't need to also include conditions for when game.random≠2, game.random≠3, etc. By definition, the condition game.random=1 means that game.random doesn't equal any other values.

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

  • umeiumei Member, PRO Posts: 21
    If you preview the game and choose easy difficulty, you will see different obstacles spawning on top of each other. There are 3 obstacles called top obstacle, bottom obstacle, top obstacle 2, bottom obstacle 2, etc.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2014
    Okay, here's the problem: you have an actor called controller that chooses a random value and spawns a moving actor called goal that in turn spawns your obstacles. The goal actor has rules to check for certain values of the random attribute value but... because it's moving and remains on the scene for a little while, it runs these rules each time the random attribute changes.

    To give you an analogy, let's say I said, "Run to the end of the field and drop a cone every time I say 'now!'" You'd start running and when I said 'now,' you'd drop a cone. Now imagine there are twenty people standing next to me and every two seconds I point to one of them and say "Run to the end of the field and drop a cone every time I say 'now!'" The next time I said 'now!' there would be two people (you and the next person) dropping a cone. The third time I said it, there would be three people... etc.

    You have the goal actor destroying when it reaches the end of the screen (the end of the field in my analogy). One way to fix this is to destroy the goal actor after it spawns obstacles.

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

  • umeiumei Member, PRO Posts: 21
    Thank you so much for the help! I really appreciate it :) It's working like a charm. I did run into a problem where score was not displaying because goal was being destroyed. I just copied the goal actor and used that for score keeping. Thanks once again!
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    You're welcome!

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

  • umeiumei Member, PRO Posts: 21

    @tatiang‌ I have an obstacle that is about 4x width of a standard obstacle. What I am trying to do is when this obstacle is spawned delay the spawning of the next obstacle. Essentially obstacles will be spawning every 2 seconds but when bigger obstacle is spawned the next one should spawn after say 3 second instead of 2 so that there is same gap in between obstacles.

    Any insight how this could be accomplished? I tried adding a rule to the timer in the controller that when obstacle.random=2 after 1 second spawn the goal. That doesn't seem to work though.

Sign In or Register to comment.