How to keep one actor on another while moving

CapCap Member Posts: 225
edited November -1 in Working with GS (Mac)
Hi,

Let's say we got two actors, both are movable and controllable with different keys. One actor is on top of the other actor. If I control the actor on the bottom, I don't want the upper actor to fall down, but to move with the actor on the bottom (except the upper actor is controlled otherwise). It's like when you stand on a driving car, you move with the speed of the car.
How to do that?

Thanks for help!

Comments

  • ValanValan Member, BASIC Posts: 410
    Use two actors. Display one depending on what is being controlled.

    Have rules for the actors and the car to keep them updated as to the position and/or graphics used.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    It sounds like you just need to constrain the X and Y of one actor to the other. Basically you create two game integer attributes (playerX and playerY).

    Then when you want to have them travel together create a rule in the "following" actor:

    Rule
    When ... (could be touch is pressed or some other condition is true)
    constrain self.position.X to game.playerX
    constrain self.position.Y to game.playerY *(see below)

    then in the "leading" actor have these two behaviors
    constrain game.plaerX to self.position.X
    constrain game.playerY to self.position.Y

    This will cause the following actor to be exactly centered on the lead actor. So to make it on top of the car you should put an offset in the following actor.

    * so to offset the guy constrain self.posiiton.Y to game.playerY+half the height of the car actor
  • CapCap Member Posts: 225
    At first I want to thank you for your answers!

    But the answers you gave me result in a non-controllable top actor, that is always bound to the actor at the bottom.

    I tried something different without the use of constrain attributes:

    the top actor moves at his own speed, if topactor.left or topactor.right keys are pressed. If not, he watches out if the actor at the bottom is moving and moves with the same speed into the same direction as the bottom actor. If all that is false and neither the top actor keys are pressed nor the actor on the bottom is moving, and only then, the top actor doesn't move at all.

    I implemented it and it seems to work.

    What do you think of this? Your opinion is important to me, as I'm really a newbie when it comes to GameSalad.
Sign In or Register to comment.