Actor follow another actor

ChirpinGamesChirpinGames Member, PRO Posts: 214
edited November -1 in Working with GS (Mac)
Hi all,
I have an actor that is being controlled by the keyboard (left and right) and was wondering if it is possible to attach another actor to it. So this second actor sits slightly above the actor1 and moves when it does?
Any help would be appreciated.
Thanks,
Mark

Comments

  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Please check the how-to in the wiki. http://gamesalad.com/wiki/how_tos

    There is a how-to specifically for that one in the Game Logic section.
  • TobyToby Member Posts: 478
    Tried this and it does not work. The following actor just zooms across the screen the the bottom LHS corner......

    What Kind of attribute type should it be? (Boolean, text, integer, real, angle, index)

    Confused.... screenshots and detail would help.

    Toby
  • TobyToby Member Posts: 478
    Ideally the behavior I'd like to create is the following.

    1. When the player moves near close proximity or over the target actor
    2. The target condition will change and it will follow the Player (Trail Behind - Attach whatever)
    3. Until a condition changes again and the object can be dropped off at another actor like HOME base etc.

    A pickup basically.

    Any ideas how this can be achieved using the - Move to & Constrain attributes

    Toby
  • TobyToby Member Posts: 478
    Had same joy, discovered the Play and Preview give completely different results. My objects are now following.

    The attribute needed to be an 'Integer'

    However, now that the objects are following me....once they reach their objective (Player Actor) they stop dead. If I move around they fly after me endlessly which is great if they reach the player they stop and freeze.

    Can this be made persistent or loop somehow? --- Read below

    EDIT: Figured it out by using a timer to loop the action

    T
  • TobyToby Member Posts: 478
    Still need some expert help with this... anyone... bueller...

    1. When the player moves near to or close proximity / over the target actor
    2. The target condition will change and it will follow the Player (Trail Behind - Attach whatever)
    3. Until a condition changes again and the object can be dropped off at another actor like HOME base etc.

    A pickup basically.

    Any ideas how this can be achieved using the - Move to & Constrain attributes
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
  • TobyToby Member Posts: 478
    Exactly, that is perfect... what are the behaviors needed to achieve this?

    Probably a really simple behavior or expression huh.

    Assume it would it work the same if the target actor went a different route or flew around the map before dropping-off?

    Toby
  • ChirpinGamesChirpinGames Member, PRO Posts: 214
    Perfect thanks CodeMonkey!
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Well what I did was this:

    Game attributes created:
    -BusX: Bus's X position (real type)
    -BusY: Bus's Y position (real type)
    -Carried: number of passengers on the bus (integer)
    -TotalDropOff: Total at the drop off to be used as an offset multiplier when passengers are added

    The Bus:
    -Save its attributes in game attributes as a reference for other actors using Constrain Attribute behaviors.
    -Usual movement behaviors

    The Wheels:
    -Constrain their positions relative to the game attributes mentioned above but with an offset
    -Rotate depending on which direction key is pressed.

    The Pickup and Dropoff:
    -2 different actors with nothing in them

    The passengers:
    -Actor attributes added:
    -->OnBus(Boolean): Is this actor on the bus
    -->SeatOffset: Offset on the bus.
    -The Pickup rule:
    --> When colliding with pickup actor AND
    --> When colliding with bus actor AND
    --> If not already on the bus(OnBus=false) [very important to prevent endless loops] AND
    --> If game.Carried < 3 (max allowed on the bus)
    ----] Change Attribute: self.OnBus = true
    ----] Change Attribute: self.Offset = game.Carried
    ----] Change Attribute: game.Carried = game.Carried + 1

    -The movement on the bus rule:
    --> If self.OnBus = true
    ----] Constrain Attribute: self.Position.X = game.BusX -14 + SeatOffset*14 (The '-14' is to start at the far left of the bus)
    ----] Constrain Attribute: self.Position.Y = game.BusY

    -The DropOff rule:
    --> If collides with DropOff actor AND
    --> If on the bus (self.OnBus = true)
    ----]Change Attribute: self.Position.X = self.Position.X-15-14*game.TotalDropOff (Filling the drop off from right to left)
    ----]Change Attribute: game.TotalDropOff = game.TotalDropOff +1
    ----]Change Attribute: game.Carried = game.Carried -1
    ----]Change Attribute: OnBus = false

    On the drop off, you could go even further and set the position of the drop off actor into game attributes to set where the passengers will position themselves after getting off the bus.
  • TobyToby Member Posts: 478
    Thanks very much. Will have a go and implement this. Might take a few goes to get it right.

    Toby
Sign In or Register to comment.