Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: tilapisha on Thu 10/03/2022 05:51:15

Title: Can my player hold an object (visually via sprites, not in inventory)?
Post by: tilapisha on Thu 10/03/2022 05:51:15
I am working on my first game, just to practice.

I want to allow my player character to hold this pie. I want the player character to hold the pie graphically when he picks up the object. Is there a way to do this using an Object property like .move, and glue the coordinates to the player character. The other solution I thought of was creating a sprite with the object, that the player sprite changes to upon collision.

Please let me know if there is an easy solution. For example: I want the player to pick up the pie, and another character, the dog will chase him around.

Title: Re: Can my player hold an object (visually via sprites, not in inventory)?
Post by: Khris on Thu 10/03/2022 07:23:12
It's possible to constantly reposition the object, yes. Something like

Code (ags) Select
function repeatedly_execute_always() {
  if (player_holding_pie) {
    oPie.X = player.x;
    oPie.Y = player.y - 30;
    if (player.Loop == 1) oPie.X -= 10; // player's facing left, move pie 10 pixels to the left
    else if (player.Loop == 2) oPie.X += 10;
  }
}


Another way is based on the fact that you can have a dummy character "follow" the player character "exactly", which basically means "draw them in the exact same place and facing the same direction". To implement that you would need to draw walkcycle frames in a new layer containing just the pie and use a new view and character to have the pie view character follow the player around.
The downside: more work.
The upside: you can animate the carried pie and make it fit exactly to the regular walkcycle frames.
(You might also have to use the above technique to change the FOLLOW_EXACTLY parameters to change whether the cake view is drawn on top or below the player)