Is it possible to overlay a sprite on top of the player using an event that follows them?

Hi everyone!
I'm working on a minigame in my RPG Maker project where the player can pick up different items and move them around. Right now, when the player picks something up, I change the player sprite to one that shows them carrying a wooden box.


However, I'd really like to show the actual item the player is carrying — for example, if they're holding a flower pot or a book, I'd like the sprite to reflect that. I could create a unique player sprite for every possible item, but I'd rather overlay a sprite on top of the player instead.


The idea is to use an event that stays on top of the player and follows them, so I can just change that event's graphic depending on the item they're holding.


I already created the graphics (a chara of each item), and I tried doing it with a parallel process event using this simple script in the event.

px = $game_player.x
py = $game_player.y
$game_map.events[97].moveto(px, py)


But it feels a bit laggy and overlaps oddly with other sprites.
Is there a better way to do this? Or maybe a plugin that could help me achieve the effect of a dynamic overlay sprite on the player?


Thanks in advance!
If it's just for a mini-game, and there aren't too many different things to carry, why not just edit the character sprite and make it carry these what? maybe 4 different items? Then just change the image of the character for as long as he's carrying the item.
If it's just for a mini-game, and there aren't too many different things to carry, why not just edit the character sprite and make it carry these what? maybe 4 different items? Then just change the image of the character for as long as he's carrying the item.
Yes, that has been my approach so far, but I keep adding different items and minigames involving item carrying. I also thought about adding NPCs that carry items, and I’ve been looking for a better way to handle this than manually editing every character with all possible items they can carry.

If I can’t find a better solution, then I’ll stick with this approach
Yes, that has been my approach so far, but I keep adding different items and minigames involving item carrying. I also thought about adding NPCs that carry items, and I’ve been looking for a better way to handle this than manually editing every character with all possible items they can carry.

If I can’t find a better solution, then I’ll stick with this approach
The problem is, you are using the map x/y coordinates for setting the new location for your overlapping event that holds the graphics. This results in your event teleporting from one coordinate to another. What you are looking for are the screen x/y coordinates.

Map coordinates are changed immediately. The effect of objects actually moving around without snapping from one tile to another comes from the update_move method in Game_Character.
If you take a look at these methods, you will see that real_x and real_y variables, besides other things, are being used. And screen x/y coordinates are based on real_x and real_y.

Therefore, in addition to updating map x/y coordinates, you also need to set the screen x/y coordinates of your event to the ones of the player. This results in having the event at the same map and screen coordinates all the time.

---

real_x and real_y attributes are read only in Game_Character. Therefore, either you change them to accessor, so you can give them new values in game, or you create a new script with an updated or additional method in order to let the coordinates be updated automatically if you say so in game. Latter could look like this:

1. New Script above Main
2.
Ruby:
class Game_Character

  #--------------------------------------------------------------------------
  # * Move to Designated Position with optional screen coordinates
  #     x : x-coordinate
  #     y : y-coordinate
  #     opt_id : id for the object in question.
  #     nil @ default, so method "moveto" works like the original
  #     Set this to 0 for the player OR any other id for the respective event.
  #     Method "moveto_opt_screen" is being called if "opt_id" is not nil.
  #--------------------------------------------------------------------------
  def moveto(x, y, opt_id = nil)
    @x = x % $game_map.width
    @y = y % $game_map.height
    @real_x = @x * 128
    @real_y = @y * 128
    @prelock_direction = 0
    moveto_opt_screen(opt_id) if opt_id
  end
 
  def moveto_opt_screen(opt_id)
    object = (opt_id == 0 ? $game_player : $game_map.events[opt_id])
    @real_x = object.real_x
    @real_y = object.real_y
  end
 
end

Or, alternatively, with an aliased method in a new script above main:

Ruby:
class Game_Character

#--------------------------------------------------------------------------
  # * Move to Designated Position with optional screen coordinates
  #     x : x-coordinate
  #     y : y-coordinate
  #     opt_id : id for the object in question.
  #     nil @ default, so method "moveto" works like the original
  #     Set this to 0 for the player OR any other id for the respective event.
  #     real_x and real_y coordinates are additionally updated if "opt_id" is not nil.
  #--------------------------------------------------------------------------
  alias moveto_original moveto

  def moveto(x, y, opt_id = nil)
    moveto_original(x, y)
    if opt_id
      object = (opt_id == 0 ? $game_player : $game_map.events[opt_id])
      @real_x = object.real_x
      @real_y = object.real_y
    end
  end
 
end

3. In game, you would then make a script call with the following:

Ruby:
Setting your event with the id 1 on the player:

$game_map.events[1].moveto($game_player.x, $game_player.y, 0)

Setting your event with the id 1 on e.g. event 5:

$game_map.events[1].moveto($game_map.events[5].x, $game_map.events[5].y, 5)
The problem is, you are using the map x/y coordinates for setting the new location for your overlapping event that holds the graphics. This results in your event teleporting from one coordinate to another. What you are looking for are the screen x/y coordinates.

Map coordinates are changed immediately. The effect of objects actually moving around without snapping from one tile to another comes from the update_move method in Game_Character.
If you take a look at these methods, you will see that real_x and real_y variables, besides other things, are being used. And screen x/y coordinates are based on real_x and real_y.

Therefore, in addition to updating map x/y coordinates, you also need to set the screen x/y coordinates of your event to the ones of the player. This results in having the event at the same map and screen coordinates all the time.

---

real_x and real_y attributes are read only in Game_Character. Therefore, either you change them to accessor, so you can give them new values in game, or you create a new script with an updated or additional method in order to let the coordinates be updated automatically if you say so in game. Latter could look like this:

1. New Script above Main
2.
Ruby:
class Game_Character

  #--------------------------------------------------------------------------
  # * Move to Designated Position with optional screen coordinates
  #     x : x-coordinate
  #     y : y-coordinate
  #     opt_id : id for the object in question.
  #     nil @ default, so method "moveto" works like the original
  #     Set this to 0 for the player OR any other id for the respective event.
  #     Method "moveto_opt_screen" is being called if "opt_id" is not nil.
  #--------------------------------------------------------------------------
  def moveto(x, y, opt_id = nil)
    @x = x % $game_map.width
    @y = y % $game_map.height
    @real_x = @x * 128
    @real_y = @y * 128
    @prelock_direction = 0
    moveto_opt_screen(opt_id) if opt_id
  end
 
  def moveto_opt_screen(opt_id)
    object = (opt_id == 0 ? $game_player : $game_map.events[opt_id])
    @real_x = object.real_x
    @real_y = object.real_y
  end
 
end

Or, alternatively, with an aliased method in a new script above main:

Ruby:
class Game_Character

#--------------------------------------------------------------------------
  # * Move to Designated Position with optional screen coordinates
  #     x : x-coordinate
  #     y : y-coordinate
  #     opt_id : id for the object in question.
  #     nil @ default, so method "moveto" works like the original
  #     Set this to 0 for the player OR any other id for the respective event.
  #     real_x and real_y coordinates are additionally updated if "opt_id" is not nil.
  #--------------------------------------------------------------------------
  alias moveto_original moveto

  def moveto(x, y, opt_id = nil)
    moveto_original(x, y)
    if opt_id
      object = (opt_id == 0 ? $game_player : $game_map.events[opt_id])
      @real_x = object.real_x
      @real_y = object.real_y
    end
  end
 
end

3. In game, you would then make a script call with the following:

Ruby:
Setting your event with the id 1 on the player:

$game_map.events[1].moveto($game_player.x, $game_player.y, 0)

Setting your event with the id 1 on e.g. event 5:

$game_map.events[1].moveto($game_map.events[5].x, $game_map.events[5].y, 5)
Thanks for your reply, as soon as I get home i will try it.

I realice the problem was that, the "lag" was actually just the jump between coordinates while the character walks betwee them. I did not know how to fix it.

Thanks again. I will come back after doing some tests!
The problem is, you are using the map x/y coordinates for setting the new location for your overlapping event that holds the graphics. This results in your event teleporting from one coordinate to another. What you are looking for are the screen x/y coordinates.

Map coordinates are changed immediately. The effect of objects actually moving around without snapping from one tile to another comes from the update_move method in Game_Character.
If you take a look at these methods, you will see that real_x and real_y variables, besides other things, are being used. And screen x/y coordinates are based on real_x and real_y.

Therefore, in addition to updating map x/y coordinates, you also need to set the screen x/y coordinates of your event to the ones of the player. This results in having the event at the same map and screen coordinates all the time.

---

real_x and real_y attributes are read only in Game_Character. Therefore, either you change them to accessor, so you can give them new values in game, or you create a new script with an updated or additional method in order to let the coordinates be updated automatically if you say so in game. Latter could look like this:

1. New Script above Main
2.
Ruby:
class Game_Character

  #--------------------------------------------------------------------------
  # * Move to Designated Position with optional screen coordinates
  #     x : x-coordinate
  #     y : y-coordinate
  #     opt_id : id for the object in question.
  #     nil @ default, so method "moveto" works like the original
  #     Set this to 0 for the player OR any other id for the respective event.
  #     Method "moveto_opt_screen" is being called if "opt_id" is not nil.
  #--------------------------------------------------------------------------
  def moveto(x, y, opt_id = nil)
    @x = x % $game_map.width
    @y = y % $game_map.height
    @real_x = @x * 128
    @real_y = @y * 128
    @prelock_direction = 0
    moveto_opt_screen(opt_id) if opt_id
  end
 
  def moveto_opt_screen(opt_id)
    object = (opt_id == 0 ? $game_player : $game_map.events[opt_id])
    @real_x = object.real_x
    @real_y = object.real_y
  end
 
end

Or, alternatively, with an aliased method in a new script above main:

Ruby:
class Game_Character

#--------------------------------------------------------------------------
  # * Move to Designated Position with optional screen coordinates
  #     x : x-coordinate
  #     y : y-coordinate
  #     opt_id : id for the object in question.
  #     nil @ default, so method "moveto" works like the original
  #     Set this to 0 for the player OR any other id for the respective event.
  #     real_x and real_y coordinates are additionally updated if "opt_id" is not nil.
  #--------------------------------------------------------------------------
  alias moveto_original moveto

  def moveto(x, y, opt_id = nil)
    moveto_original(x, y)
    if opt_id
      object = (opt_id == 0 ? $game_player : $game_map.events[opt_id])
      @real_x = object.real_x
      @real_y = object.real_y
    end
  end
 
end

3. In game, you would then make a script call with the following:

Ruby:
Setting your event with the id 1 on the player:

$game_map.events[1].moveto($game_player.x, $game_player.y, 0)

Setting your event with the id 1 on e.g. event 5:

$game_map.events[1].moveto($game_map.events[5].x, $game_map.events[5].y, 5)


Thank you very much! this works perfectly.

Original thread: https://forums.rpgmakerweb.com/threads/is-it-possible-to-overlay-a-sprite-on-top-of-the-player-using-an-event-that-follows-them.178385/