NPC Running Away Pathfind script

Sausage_Boi

Game Dev. "Artist."
Veteran
Joined
Sep 10, 2014
Messages
1,733
Reaction score
681
First Language
Americanese
Primarily Uses
RMVXA
Hello! I was wondering if anyone could find/create a simple script that makes it so NPCs don't get stuck on objects when they are running away from you, or would any ol' Pathfind script do that for me?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
A pathfinding script finds the quickest path to a target. In the case of running away, you don't have a target. You potentially have many. How would you choose which tile to run to? Selecting a random tile that is X tiles away from the player could see you trying to reach a target that's unreachable (the pathfinding script would not work).


If you're using a move route, you could just add a random movement in there every 4-5 steps or so. So if they're moving away and there's an obstacle, there's a chance that they'll side-step it after trying to go through it a few times. Of course that won't help if they go into an enclosed area.
 

Sausage_Boi

Game Dev. "Artist."
Veteran
Joined
Sep 10, 2014
Messages
1,733
Reaction score
681
First Language
Americanese
Primarily Uses
RMVXA
thanks for the tip. I was trying to keep the map so that there aren't any enclosed areas that NPCs can get trapped in. I could swear TheoAllen (maybe someone else?) had given me a snippet of code, or a short script that prevented NPCs from hanging up on obstacles, but I can't find it anywhere. It was from nearly a year ago.

One more question: If I set up a map that loops horizontal and vertical, and I use an available pathfinding script, could I set the NPCs to run away from the player to a certain place on the map, and switch event pages to make them run to a new position on the map when they reach X,Y position on the map?
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
probably, though how are you going to figure out when to switch it? And you could probably do it without multiple event pages, if you're using another event to track where they are and when to go to the next point.
 

Sausage_Boi

Game Dev. "Artist."
Veteran
Joined
Sep 10, 2014
Messages
1,733
Reaction score
681
First Language
Americanese
Primarily Uses
RMVXA
probably, though how are you going to figure out when to switch it? And you could probably do it without multiple event pages, if you're using another event to track where they are and when to go to the next point.
Well, I went back and looked over my original plan, and found it wasn't possible to use variables to store map position of moving events like you can with the player. So, I have no idea how I am going to figure out when to switch... I am currently using a parallel process for another thing, I could just add event tracking info for NPCs, but I don't see an option to do that.
 

skymen

Veteran
Veteran
Joined
Aug 26, 2013
Messages
46
Reaction score
5
First Language
French
Primarily Uses
What you may want to do is a thing like this:
Move route: This event
     Run away from the player
Play in loop
Ignore if impossible

Start of loop
Move route: This event
     A step Upwards
Ignore if impossible


Move route: This event
     A step Rightwards
Ignore if impossible


Move route: This event
     A step Downwards
Ignore if impossible


Move route: This event
     A step Leftwards
Ignore if impossible


Move route: This event
     A step an a random direction
Ignore if impossible
End of loop

This may work without the loop thing


EDIT: I tried it myself, it kinda work, but it's also really messy. This may work properly if we could check for event collision :s

EDIT 2: Actually there is a way: Using RMEx (http://rmex.github.io/) scripts (Rpg Maker Extender), you can check for event's position, and then see if it has moved or not, and then processing the whole thing with conditions in loops.
 

skymen

Veteran
Veteran
Joined
Aug 26, 2013
Messages
46
Reaction score
5
First Language
French
Primarily Uses
I think because you can't get the efent's position.
Erm, if you actually could, that would solve the whole thing :)
 

Sausage_Boi

Game Dev. "Artist."
Veteran
Joined
Sep 10, 2014
Messages
1,733
Reaction score
681
First Language
Americanese
Primarily Uses
RMVXA
@Shaz, I guess what I should say is I can't find any method to store location information for events via variables. Like when you set player X and Player Y to a variable, I don't see a method to store the same information for a moving event.
 

MeowFace

Meow
Veteran
Joined
Feb 22, 2015
Messages
1,034
Reaction score
184
First Language
Meowish
Primarily Uses
use these script calls in control variable's script box:

$game_map.events[id].x

$game_map.events[id].y

id = event's id
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c

Forum statistics

Threads
105,857
Messages
1,017,015
Members
137,563
Latest member
MinyakaAeon
Top