[Solved] NPC to imitate player movement

Hey guys,

I'm trying to make a sort of ghost npc to imitate the player's movement.

Through eventing, I can get npcs to move in the same direction as me, but it isn't quite a mirror. (They are just parallel processes that wait on arrow key presses and then take a movement route accordingly.) From top to bottom:

  1. The actual player.
  2. Event that waits until movement finishes. (Normal speed, high frequency) The npc's speed doesn't match mine very well and the walk cycle looks a little clunky regardless of settings.
  3. Event that moves without waiting. (Normal speed, normal frequency) It appears to match my speed better. Then I realized that the npc always moves 1 extra tile.
wu0754.jpg


Side note, I don't need the movement to match perfectly, but I'd like it if the ghost/clone could take a few steps without being obviously off.

Any ideas/feedback would be highly appreciated. Thanks in advance. 🙂
"Ghost npc to imitate the player's movement." That's an interesting idea! Never tried that myself. Are you just using the default scripts? I'm sure there are multiple ways of doing this using a movement script, but it could be complicated and require modifiying script integers. By default, I believe the player character's movement values are defined somewhere in the RGSS3 script, seems to be slightly faster than you need it to be, although I'm not sure where it is located... It is possible to change the defualt player speed and frequency within the default scripts, or you can find a custom script as well.
I have tried to do something like this and found that events and the "Actor" are on totally separate methods. With the parallel processes, they wait for user interaction but it has to run down the the entire event page to see it (which causes the delay your image is producing). I found what works is to have the events check player position and move accordingly. There will still be a slight delay but it will be more accurate as it's calculating movements based on math rather then button presses.

For example,

If you have a player at 80, 80 and moves to 80, 81

and

If you have an event at 80, 83 Once the player moves to 81, you make it so that the event moves to 84.

(this is easier said then done however.)

Another method you could try that might be a bit less intimidating is to simpley hide the actor and have the player think that the event is the actor though if you have a map larger then your screen size it might be a bit difficult to track the camera movement.

The only other way you can do this to have it exact would be through  a script unfortunately.
Here's one to try out:

class Game_Event def page_notes return '' if @page.nil? || @page.list.empty? @page.list.select {|c| [108,408].include?(c.code) }.map {|c| c.parameters[0] }.join($/) end def move_with_player? page_notes =~ /<move_with_player>/i end def move_by_input if move_with_player? && movable? && !$game_map.interpreter.running? @move_speed = $game_player.move_speed @move_frequency = $game_player.move_frequency move_straight(Input.dir4) end end alias update_move_by_input update def update move_by_input update_move_by_input end def movable? return false if moving? return true end def dash? move_with_player? ? $game_player.dash? : super end def debug_through? move_with_player? ? $game_player.debug_through? : super endendJust add a comment to the specific page of the event you want to mimic the player's movement: <move_with_player>If you dash, the event will dash with you as well, and if you are playing from the editor and use CTRL to go through walls, the event will follow as well. Is this satisfactory?
Yes, It's perfect!!

I wasn't expecting to get a solution so quickly, and you even included dashing which i didn't mention.

Thanks so much for taking the time FenixFyreX.  😍:

--

@boldpaste2: Thanks for posting some ideas! I did think about hiding the player and making a psuedo-player, but like you mentioned the camera doesn't follow the dummy. Other concerns i had thought of were caterpillar followers, and dashing with shift.
It's great that you found a solution 😀

I am going to actually bookmark this page because Fenix's script could have saved me in several situations. ^^
Here's one to try out:

class Game_Event def page_notes return '' if @page.nil? || @page.list.empty? @page.list.select {|c| [108,408].include?(c.code) }.map {|c| c.parameters[0] }.join($/) end def move_with_player? page_notes =~ /<move_with_player>/i end def move_by_input if move_with_player? && movable? && !$game_map.interpreter.running? @move_speed = $game_player.move_speed @move_frequency = $game_player.move_frequency move_straight(Input.dir4) end end alias update_move_by_input update def update move_by_input update_move_by_input end def movable? return false if moving? return true end def dash? move_with_player? ? $game_player.dash? : super end def debug_through? move_with_player? ? $game_player.debug_through? : super endendJust add a comment to the specific page of the event you want to mimic the player's movement: <move_with_player>If you dash, the event will dash with you as well, and if you are playing from the editor and use CTRL to go through walls, the event will follow as well. Is this satisfactory?
Hey FenixFyreX. Is it possible to make this script 8-direction compatible? I've been messing around with it and can't get it to work as of yet... I'm using Hime's Eight-Directional Movement script.
Nevermind... I figured it out!
This is a necro but, any chance of someone fixing the script with the correct lay-out?

Here's one to try out:

class Game_Event def page_notes return '' if @page.nil? || @page.list.empty? @page.list.select {|c| [108,408].include?(c.code) }.map {|c| c.parameters[0] }.join($/) end def move_with_player? page_notes =~ /<move_with_player>/i end def move_by_input if move_with_player? && movable? && !$game_map.interpreter.running? @move_speed = $game_player.move_speed @move_frequency = $game_player.move_frequency move_straight(Input.dir4) end end alias update_move_by_input update def update move_by_input update_move_by_input end def movable? return false if moving? return true end def dash? move_with_player? ? $game_player.dash? : super end def debug_through? move_with_player? ? $game_player.debug_through? : super endendJust add a comment to the specific page of the event you want to mimic the player's movement: <move_with_player>If you dash, the event will dash with you as well, and if you are playing from the editor and use CTRL to go through walls, the event will follow as well. Is this satisfactory?
@BCj
Ruby:
class Game_Event
 
  def page_notes
    return '' if @page.nil? || @page.list.empty?
    @page.list.select {|c| [108,408].include?(c.code) }.map {|c| c.parameters[0] }.join($/)
  end
 
  def move_with_player?
    page_notes =~ /<move_with_player>/i
  end
 
  def move_by_input
    if move_with_player? && movable? && !$game_map.interpreter.running?
      @move_speed = $game_player.move_speed
      @move_frequency = $game_player.move_frequency
      move_straight(Input.dir4)
    end
  end
 
  alias update_move_by_input update
  def update
    move_by_input
    update_move_by_input
  end
 
  def movable?
    return false if moving?
    return true
  end
 
  def dash?
    move_with_player? ? $game_player.dash? : super
  end
 
  def debug_through?
    move_with_player? ? $game_player.debug_through? : super
  end
 
end
Try this
Spoiler: NPC copy movement
Ruby:
# FenixFyreX
# Just add a comment to the specific page of the event you want
# to mimic the player's movement: <move_with_player>If you dash,
# the event will dash with you as well, and if you are playing
# from the editor and use CTRL to go through walls, the event
# will follow as well. Is this satisfactory?

class Game_Event
    def page_notes
        return '' if @page.nil? || @page.list.empty?
        @page.list.select {|c| [108,408].include?(c.code) }.map {|c| c.parameters[0] }.join($/)
    end
    def move_with_player?
        page_notes =~ /<move_with_player>/i
    end
    def move_by_input
        if move_with_player? && movable? && !$game_map.interpreter.running?
            @move_speed = $game_player.move_speed
            @move_frequency = $game_player.move_frequency
            move_straight(Input.dir4)
        end
    end
    alias update_move_by_input update
    def update
        move_by_input
        update_move_by_input
    end
    def movable?
        return false if moving?
        return true
    end
    def dash?
        move_with_player? ? $game_player.dash? : super
    end
    def debug_through?
        move_with_player? ? $game_player.debug_through? : super
    end
end
Well see what happens when you don't refresh the page for a while.
*ninja'd

Going to close this now.

Original thread: https://forums.rpgmakerweb.com/threads/solved-npc-to-imitate-player-movement.31413/