Theo - Pathfinding and Event Chase Player

Discussion in 'RGSS3 Scripts (RMVX Ace)' started by TheoAllen, Jan 8, 2015.

  1. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,451
    Likes Received:
    5,042
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    Pathfinding and Event Chase Player
    Version 1.0b
    Type : Field script
    Introduction
    This script simply for determine the shortest path from started from a character position to target coordinate.

    Features :
    • Determine the shortest path
    • Chase the player in smarter way
    Video Preview


    Download link :
    Click here
     
    Last edited: Jul 30, 2018
    #1
  2. Sophism

    Sophism Veteran Veteran

    Messages:
    36
    Likes Received:
    6
    First Language:
    English
    OK! So I tested it out in my hedge maze, and the event was able to find a path almost perfectly most of the time.

    However, in a couple of instances, despite using Ctrl to walk through a wall before it reached me, the event seemed to first go to my previous position before adjusting and finding a new path. After some time playing hide and seek, it just stopped moving altogether, although it took a couple of minutes for that to happen.

    The event in question was set up to the highest frequency and moving at twice the regular player speed. Its move route was set up with a single goto_player script call and repeat action toggled on.

    I'll test it out a bit more later, to see if I can reliably reproduce the event halting the pathfinding.
     
    Last edited by a moderator: Jan 10, 2015
    #2
    TheoAllen likes this.
  3. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,451
    Likes Received:
    5,042
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    Did you put <chase player> comment in event?

    It will acts like an autonomous movement. So you dont need to manually put move route

    New path will be refreshed in once per second
     
    Last edited by a moderator: Jan 10, 2015
    #3
  4. Sixth

    Sixth Veteran Veteran

    Messages:
    2,130
    Likes Received:
    800
    First Language:
    Hungarian
    Primarily Uses:
    RMVXA
    This script is just simply perfect!


    Now I can discard my long and tedious eventing and instead use a simple comment for my guards and monsters!


    You just saved me hell of a lot time with this, thanks a lot!


    I expected some FPS loss, especially with multiple chasing events, but to my surprise, there was no significant FPS loss. o.o


    Extra thanks for this! :)
     
    #4
    TheoAllen likes this.
  5. Sophism

    Sophism Veteran Veteran

    Messages:
    36
    Likes Received:
    6
    First Language:
    English
    I hadn't tried <chase player> yet, sorry. The wording in the instructions seemed to imply it would force the player to chase after the event instead.

    I have tried that now, and while it didn't lock up, what did happen was that whenever the event had to redo the path, (Such as when I ran through one of the maze walls with Ctrl.) it would drop FPS down from 60 to 10-15 for a few seconds, then stabilize until I did it again. This may be an issue with the size of the map I tested this on.
     
    #5
  6. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,451
    Likes Received:
    5,042
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    The FPS drop is because the event didn't find your position which is your current position is in unpassable / can't be found. And the event forced to search around the whole map. So, the issue came from the CTRL / Debug Through
     
    #6
  7. Sixth

    Sixth Veteran Veteran

    Messages:
    2,130
    Likes Received:
    800
    First Language:
    Hungarian
    Primarily Uses:
    RMVXA
    Ahoy, Theo!


    I had a little fun with this script while I tried something out and I noticed something rather odd...


    I had my event set up this way:


    Page 1:


    - Only set up some commands in the autonomous movement.


    - The event moved left and right between 2 points in a straight line. I used your script calls to do this, one find_path(x,y) for each points.


    Page 2:


    - Requires self-switch 'A' to be turned ON.


    - Contains only the <chase player> comment.


    - Fixed auto-move route here.


    The event's self switch 'A' is turned ON automatically when the player has been spotted (I use a proximity script for this with line of sight feature).


    So, what should happen is, when the player did not alerted the guard, it moves left and right, patrolling the area. But when the player has been spotted, the guard will start to chase the player. This works perfectly fine.


    When the player successfully managed to hide for a short time, the event's self-switch will be turned off. This initiates the find_path(x,y) auto-movement again for the guard, so no matter where the player lured the guard, it will return to it's original position. And this works well too.


    But after the guard has arrived it's original position and moves to the 2nd point, the find_path(x,y) auto-move route fails. It will run another additional path before returning to the 1st spot again. This additional path seems to have a pattern, but maybe I was just watching the blasted guard too long. :D


    I wonder what could cause this? I tried to figure it out, but nothing seemed off in the script for me.


    It seems to me that somehow the last move route executed from the <chase player> page goes to the end of the first page's auto-move route.


    Just wanted to report this odd behavior, hoping that you can fix it. *-*
     
    #7
  8. Jeysonmcfly

    Jeysonmcfly Just a random Joe Schmoe Veteran

    Messages:
    54
    Likes Received:
    15
    Location:
    Soon to be Canadian
    First Language:
    English
    I'm thinking of using this to create somewhat smarter AI for a warcraft 2 style RTS/ god/village simulation game. the idea is that the player controls things via a cursor and can select characters then order them to do things. since the cursor would function as the player character, would it be possible for the NPC to go to a specific player-specified coordinate instead of just where the player is with this script?
     
    #8
  9. UNphiltered_khaos

    UNphiltered_khaos Game Dev. Artist. Veteran

    Messages:
    1,730
    Likes Received:
    640
    Location:
    Montucky
    First Language:
    Americanese
    Primarily Uses:
    N/A
    Does this script have the ability to send NPCs to a location based on Variables?
    I.E. If I use a parallel process to store player X,Y in a variable, is there any method to call that information and use it to move the NPC to those coordinates?
     
    #9
  10. Sixth

    Sixth Veteran Veteran

    Messages:
    2,130
    Likes Received:
    800
    First Language:
    Hungarian
    Primarily Uses:
    RMVXA
    You would use:


    find_path($game_player.x,$game_player.y)


    No variables, no needless parallel process events, especially no parallel process events which update a variable all the time.


    You use this in a "Set Move Route" script call, not with a simple script call command, so the target of the script call will be set via that target selector thing at the top left corner of the popup window where you can select "This Event", "Player", or a specific event.


    If you need to use variables for X and Y position, you use this:


    find_path($game_variables[ID],$game_variables[ID])


    But do not update any variables/switches/self-switches in any constantly updating parallel process event, that will drop the FPS, and it is not needed at all.
     
    #10
  11. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,451
    Likes Received:
    5,042
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    Just realized I had a topic for this, so well there goes the update after 3 years! :D
    All of you who are using this script should use this version onwards!

    @Sixth sorry for VERY LATE REPLY. But I managed to squash game breaking bug because I unintentionally change the original move route instead of altering and copying it, that as the result the event behaviour becomes so odd. Maybe that is also why.
     
    #11
  12. Cerveau

    Cerveau Villager Member

    Messages:
    24
    Likes Received:
    6
    First Language:
    Tagalog
    Does event chase offscreen persist in the new update?

    The last time I remember is that when the player outrun the chasing event lets say like 10 squares outside the monitor, the event halts the chase to dead stop but if player reenters event vicinity it will resume chasing.
     
    #12
  13. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,451
    Likes Received:
    5,042
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    The new update only fixes the weird behavior on using find_path on event command move route, not autonomous movement. And it doesn't touch anything regarding the event chase itself, so maybe it still is.

    Here is the thing. By default, all autonomous movement stops once the event is far away from screen. Which it can be considered as either bug or feature. But anyway, I might try to look at it tomorrow, and see if I could make the event chase keep persistent even if it went off screen.

    Thanks for reporting though.
     
    #13
    Cerveau likes this.
  14. bigcalsworld

    bigcalsworld Veteran Veteran

    Messages:
    79
    Likes Received:
    53
    First Language:
    English
    Hi. Great script! Tried a couple of similar ones and they didn't work, so seeing this one actually do what I wanted was awesome :D.

    Buuuut... did you ever look into the events moving when off screen? Right now I'm using it for NPC's in villages going home at a certain time, but of course they only move if I'm on screen with them, which isn't ideal lol. :)
     
    #14
  15. TheoAllen

    TheoAllen Self-proclaimed jack of all trades Veteran

    Messages:
    4,451
    Likes Received:
    5,042
    Location:
    Riftverse
    First Language:
    Indonesian
    Primarily Uses:
    RMVXA
    This is an intended design from the RM itself. And it has nothing to do with my script.
    If you insist to make the event movement's keep being updated, try this patch. I'm not responsible for whatever lags you're encountering.
    Code:
    class Game_Event
      def near_the_screen?(*args)
        return true
      end
    end
     
    #15
    bigcalsworld likes this.

Share This Page