Can my player hold an object (visually via sprites, not in inventory)?

Started by tilapisha, Thu 10/03/2022 05:51:15

Previous topic - Next topic

tilapisha

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.


Khris

It's possible to constantly reposition the object, yes. Something like

Code: ags
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)

SMF spam blocked by CleanTalk