Randomly stopping and resuming movement in a 'move back and forth' cycle

Asobu_GamesAsobu_Games PRO Posts: 261
edited November -1 in Working with GS (Mac)
Hi all, this is my first post so sorry in advance for the beginner question. I tried searching but could not find a specific answer. I have just started with GameSalad a few days ago and am trying to get a handle on it. Although I have zero coding background I am really impressed with it so far!

My goal at the moment is to get a sliding door to open and shut (move left/right) repeatedly. The idea is that sometimes an enemy will be behind the door. So far I have achieved the left/right movement cycle by having the 'door' actor move left and then right at a certain x position and vice versa. No problem there.

My question is how to get the door actor to stop (in the left or right position) for a moment before moving again in the opposite direction. In other words I want it to move left > stop > move right > stop > etc. At the moment it's just right > left > right > left etc.

Also I'd like to randomize this action if possible. eg. open > stop for a random amount of time > close > stop for a random time, etc.

Can anyone help out? Thanks, any help is much appreciated. :)

Comments

  • old_kipperold_kipper Member Posts: 1,420
    You can use timers to open, and close the door, and fire the rule set with a timer that has a random time set between 2 numbers. Also create an actor self attribute index to store the state of the door.

    I would do it something like this after creating the actor self attribute... perhaps 'self_open'

    rule attribute self.door_open = 0

    then place a timer in the rule

    Timer after random(3,15)

    interpolate door open 1 sec linear for movement or you could just place an animation of the door opening.. depends how you are doing it), and add a-

    change attribute self.dooropen to 1

    then another timer after 1 sec change self.dooropen to 2

    I use timers like this as it avoid catches where you want something to happen depend on the door actually being open and not when it is opening....

    then in another rule

    if attribute self.door_open= 2

    timer after random(2,5) interpolate door closed 1 sec linear, change attribute self.door-open to 3,

    timer, after 1 sec change attribute self.door_open to 0

    this way the whole thing would loop.

    I have laid it out roughly but hopefully you will understand it.

    good luck kipper
  • Asobu_GamesAsobu_Games PRO Posts: 261
    Thanks so much for the help. I'll have a go at it tonight when I get home. :) Fingers crossed!
Sign In or Register to comment.