Random movement blocks - collect "reward"

LemonKicksLemonKicks Member, PRO Posts: 64

Hello everyone,

I am new to GameSalad and I really hope you can help me in the right direction with my question.
I have added a simple image for your reference. The BlOCK has to randomly move up and down, a "reward" becomes visible as it goes up and the player has to "collect" it for points. How do I set up the block and reward to move up and down randomly (and faster as the game becomes more difficult).

Thanks so much!

Best regards,

Esther

Comments

  • JScottJScott Member Posts: 143

    Use a variable for the blocks speed, and change the variable every X seconds. You can increase the speed variable, or use the random function.

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

    What does "randomly" mean in this case? Does the upper block move at a constant speed, all the way to the top of its range, then back to the bottom of its range, and then pause for a random delay before repeating? Or does the upper block move up and down within its entire possible range in a spastic sort of motion (e.g. it might move up 40 pixels, then down 5, then up 2, then down 15, then up 20, etc.)? And does the speed vary as well?

    Keep in mind that there is no way to tell if an actor in GameSalad is "visible." To achieve that effect, you'll have to do something like checking the Y position of the upper block actor and then if the lasso collides with the reward when Y>[some value], give the player the reward.

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

  • LemonKicksLemonKicks Member, PRO Posts: 64

    Thank you all for your help! Really appreciate it :smiley:

    @tatiang - "randomly" means the upper block moving up and down within its entire possible range, but the speed must vary (so the player has to "time" getting the reward, he can also be too quick or too slow if the block is in the way). Hope I'm explaining it clearly.

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

    That shouldn't be hard. Just use an attribute for the duration of your interpolate behavior(s). Then alter that value to have the desired effect.

    So something like this (assuming a bottom Y of 100 and a top Y of 300, and a travel duration of 0.2 to 0.6 seconds each direction):

    When self.Position.Y = 100
         Change attribute self.speed to random(2,6)/10
         Change attribute self.newY to 300
         Interpolate self.Position.Y to self.newY [duration self.speed]

    When self.Position.Y = 300
         Change attribute self.newY to 100
         Interpolate self.Position.Y to self.newY [duration self.speed]

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

  • LemonKicksLemonKicks Member, PRO Posts: 64

    Thank you for your reply and explanation :smiley: !!!
    Really appreciate the help!

  • LemonKicksLemonKicks Member, PRO Posts: 64
    edited January 2017

    Hope you don't mind my follow-up question. I am confused about the difference between self.speed and the travel duration. How do I set up the attribute for duration if its not the same as self.speed?

    Thanks so much!

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

    The Interpolate behavior changes the value of an attribute over time. That time is the "duration" of the change. I chose to use self.speed in the Interpolate behavior. There isn't a need for a separate duration attribute... that IS the duration attribute. I was just trying to explain what that attribute is doing.

    If you try it, you'll see what happens when you change the value of self.speed (e.g. 0.2 seconds or 1.5 seconds, etc.).

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

  • LemonKicksLemonKicks Member, PRO Posts: 64

    @tatiang Awesome - thank you! Sorry, I am still a noob :blush:

  • 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

  • LemonKicksLemonKicks Member, PRO Posts: 64
    edited January 2017

    @tatiang Last question, I promise. I think I am doing something wrong, because the upper block (transporter top in my screenshot) is moving up and down perfectly except not randomly. What am I doing wrong? I have been searching youtube tutorials and the forum but can't find anything. What am I setting up wrong?

  • LemonKicksLemonKicks Member, PRO Posts: 64

    It is fixed - I set the speed attribute at integer, but it had to be real. Still got a lot to learn.Thanks for all your help @tatiang :smiley:

Sign In or Register to comment.