Karanum

Karanum's Pathfinding Script

27 posts in this topic

Pathfinding v1.0

by Karanum

 

Introduction

Pathfinding is an important part of video games nowadays. Even in RPG Maker, where it forms an important part of

tactical battle systems, or even events with variable starting points. This script offers an easy and reliable way to get

your events from A to B in the least time possible.

 

Features

- 4 different pathfinding methods

- Based on Dijkstra's algorithm

- Minimal lag (increases for large maps though)

 

Planned

- Upgrade to A* algorithm (it's faster!)

- Include diagonal movement option

- Add collision checking with events

 

Instructions

Place the script in the Materials section, above Main.

In an event, use the Script command and simply enter the method you want to use.

Further instructions are found in the header of the script.

 

Demo

Download

The demo was made with the Japanese version of Ace. I might translate the menus if people have problems with it.

 

Script

 

 

#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - Pathfinding script by Karanum -
#----------------------------------------------------------------------------
# This pathfinding script is based off a simplified version of Dijkstra's
# algorithm. It's mainly made for calculating paths over small distances,
# but also provides some methods for longer calculations.
#
# It adds 4 different methods for calculating the path and 1 method to check
# whether an event is pathfinding or not.
# For all of these methods, the x and y are the end coordinates and the id is
# the id of the event that has to run the pathfinding method. When left out, the
# id will always default to 0. **
# Setting through? allows you to change the pathfinding event's passability.
# This setting defaults to true if you don't set it.
#
#
#   - walk_to_straight( x, y, id, through? )
#	   This performs simple pathfinding, using only a part of the map.
#	   It can't find long detours, but it's the least expensive method.
#	   This should be used for basic events that don't require advanced
#	   pathfinding.
#
#   - walk_to( x, y, id, through? )
#	   This is the most basic form of the pathfinding algorithm, although it
#	   can lag when using large maps or when there is no path to the endpoint.
#	   This is the most balanced pathfinding method, able to find paths of up
#	   to a 1000 tiles.
#
#   - walk_to_short( x, y, id, through? )
#	   Basically a lesser version of the walk_to method.
#	   It can find paths of up to a 100 tiles and is best for larger maps.
#
#   - walk_to_long( x, y, max_steps, id, through? )
#	   This method lets you specify the maximum amount of tiles the path can
#	   be, but will take a while to calculate the path. This method is best
#	   for pathfinding over long distances, although it takes the longest.
#	   This method will only lag the calling event, not your entire game.
#
#   - pathfinding?( id )
#	   This method returns true when the specified event is currently going
#	   through one of the above methods. Otherwise it returns false.
#
#
# ** NOTE: As event id, you can use 0 for 'This Event' and -1 for 'Player'
#
# Don't change anything past this point if you don't know what you're doing.
# It can make your game crash when you try to call one of the methods.
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - Game_Character -
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
class Game_Character
 attr_accessor :target_x
 attr_accessor :target_y
 attr_reader   :path_through
 attr_reader   :pathfinding
 attr_reader   :distance_map

 #--------------------------------------------------------------------------
 # Game_CharacterBase's update override
 # May cause incompatibility with other scripts that also override this
 #--------------------------------------------------------------------------
 def update
update_animation
return update_jump if jumping?
return update_move if moving?
return update_path if pathfinding?
return update_stop
 end

 #--------------------------------------------------------------------------
 # Update pathfinding movement
 #--------------------------------------------------------------------------
 def update_path
if !@distance_map
  return
end

if (@x == @target_x) and (@y == @target_y)
  puts "[Pathfinding] Pathfinding completed"
  @through = false if @path_through
  @pathfinding = false
  return
end

next_dir = find_next_tag(@distance_map, @x, @y)
if next_dir == 0
  puts "[Pathfinding] Could not find path to endpoint"
  puts "[Pathfinding] If a path exists, try increasing the amount of iterations"
  @through = false if @path_through
  @pathfinding = false
  return
end

move_straight(next_dir)
 end

 #--------------------------------------------------------------------------
 # Check if currently pathfinding
 #--------------------------------------------------------------------------
 def pathfinding?
if @pathfinding
  return @pathfinding
else
  return false
end
 end

 #--------------------------------------------------------------------------
 # Obtain array with distance map from $game_map
 #--------------------------------------------------------------------------
 def walk_to(x, y, iterations=1000, long_mode=false, short_mode=false, passthrough=true)
puts "[Pathfinding] Starting pathfinding"
@pathfinding = true
@path_through = passthrough
@through = true if @path_through

@target_x = x
@target_y = y

@distance_map = $game_map.find_path(self, x, y, iterations, long_mode, short_mode)
puts "[Pathfinding] Distance map generated"
 end

 #--------------------------------------------------------------------------
 # Find next tile to walk to
 #--------------------------------------------------------------------------
 def find_next_tag(map, x, y)
current_tag = map[y][x]
if(current_tag == -1)
  return 0
end

if y != (map.length - 1)
  if map[y+1][x] == current_tag - 1
	return 2
  end
end

if x != 0
  if map[y][x-1] == current_tag - 1
	return 4
  end
end

if y != 0
  if map[y-1][x] == current_tag - 1
	return 8
  end
end

if x != (map[y].length - 1)
  if map[y][x+1] == current_tag - 1
	return 6
  end
end

return 0

 end
end

#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - Game_Map -
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
class Game_Map

 #--------------------------------------------------------------------------
 # Check adjacent tiles for passability
 #--------------------------------------------------------------------------
 def check_adjacent_panels(x, y)
adjacent_panels = Array.new(4, false)

if y != (height - 1)
  if passable?(x, y, 2) and passable?(x, y+1, 8) #Down
	adjacent_panels[0] = true
  end
end

if y != 0
  if passable?(x, y, 8) and passable?(x, y-1, 2) #Up
	adjacent_panels[2] = true
  end
end

if x != (width - 1)
  if passable?(x, y, 6) and passable?(x+1, y, 4) #Right
	adjacent_panels[3] = true
  end
end

if x != 0
  if passable?(x, y, 4) and passable?(x-1, y, 6) #Left
	adjacent_panels[1] = true
  end
end

return adjacent_panels
 end

 #--------------------------------------------------------------------------
 # Create an array with a distance map to the endpoint
 #--------------------------------------------------------------------------
 def find_path(event, x, y, iterations=1000, long_mode=false, short_mode=false)
map_array = Array.new(height) { Array.new(width, -1) }
map_array[y][x] = 0
current_tag = 0
current_iteration = 0

low_x = 0
low_y = 0
high_x = width - 1
high_y = height - 1

if short_mode
  low_x = [event.x, x].min - 2
  low_y = [event.y, y].min - 2
  high_x = [event.x, x].max + 2
  high_y = [event.y, y].max + 2
end

iterations.times do
  current_iteration = current_iteration + 1
  for map_y in (low_y..high_y)
	for map_x in (low_x..high_x)
	  if map_array[map_y][map_x] == current_tag
		adjacent_panels = check_adjacent_panels(map_x, map_y)
		if adjacent_panels[0]
		  if map_array[map_y+1][map_x] == -1
			map_array[map_y+1][map_x] = current_tag + 1
		  end
		end
		if adjacent_panels[1]
		  if map_array[map_y][map_x-1] == -1
			map_array[map_y][map_x-1] = current_tag + 1
		  end
		end
		if adjacent_panels[2]
		  if map_array[map_y-1][map_x] == -1
			map_array[map_y-1][map_x] = current_tag + 1
		  end
		end
		if adjacent_panels[3]
		  if map_array[map_y][map_x+1] == -1
			map_array[map_y][map_x+1] = current_tag + 1
		  end
		end
	  end
	end
  end
  current_tag = current_tag + 1
  if map_array[event.y][event.x] != -1
	return map_array
  end
  if (current_iteration % 20 == 0) and long_mode
	Fiber.yield
  end
end

return map_array
 end
end

#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# - Game_Interpreter -
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# Changes:
#   - Added walk_to(x, y, id)
#   - Added walk_to_short(x, y, id)
#   - Added walk_to_long(x, y, iterations, id)
#   - Added walk_to_straight(x, y, id)
#   - Added pathfinding?(id)
#=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
class Game_Interpreter
 def walk_to(x, y, id=0, passthrough=true)
character = get_character(id)
character.walk_to(x, y, 1000, false, false, passthrough)
 end

 def walk_to_short(x, y, id=0, passthrough=true)
character = get_character(id)
character.walk_to(x, y, 100, false, false, passthrough)
 end

 def walk_to_long(x, y, iterations, id=0, passthrough=true)
character = get_character(id)
character.walk_to(x, y, iterations, true, false, passthrough)
 end

 def walk_to_straight(x, y, id=0, passthrough=true)
character = get_character(id)
character.walk_to(x, y, 1000, false, true, passthrough)
 end

 def pathfinding?(id=0)
character = get_character(id)
return character.pathfinding?
 end
end

 

 

 

FAQ

Q: How can I decrease the lag when using pathfinding?

A: Use a smaller map if possible, otherwise use the walk_to_straight method. It's less flexible, but lighter.

 

Q: How to increase the amount of steps without walk_to_long's processing time?

A: Use the following script call instead, replacing id, x, y and steps with the numbers you want:

character = get_character(id)
character.walk_to(x, y, steps)

 

Giving Credit

When using this in your game, give credit to Karanum.

If you want to use this script in a commercial game, contact me first.

 

Author's Notes

I found out there's another pathfinding script out there by Khas. I must admit, I haven't checked it out yet, and I don't

know exactly what functions Khas' script has. However, I urge everyone to check that one out as well and see which

of the scripts works best for you.

Share this post


Link to post
Share on other sites

This script is awesome and exactly what I've been looking for! The one issue I have with it though is that if i choose to execute path finding on several events they don't collide with each other or the player which is weird visually. I was wondering if future updates will include the option of path finding that take moving events or other path finding events or the player into considerations.

 

 

Note: I have tried Khas' script which does collide with other events but if it does it would end the path which is an undesirable result.

Share this post


Link to post
Share on other sites
Q: How can I decrease the lag when using pathfinding?

A: Use a smaller map if possible, otherwise use the walk_to_straight method. It's less flexible, but lighter.

 

So there's no way to avoid checking the entire map for the shortest valid path?

Edited by Tsukihime

Share this post


Link to post
Share on other sites

okay nevermind, finally figured out that through? represented the event passability. Then I discovered that if something moves into an event's decided path it will wait until it moves out of the way before continuing. Is there a way to make it so that if something blocks it, it will recalculate?

Share this post


Link to post
Share on other sites

I would not re-calculate because you run the risk of going into an infinite loop.

Or if code is written to prevent that (eg: memoization, no-backtrack, etc) at least you're definitely doing a lot of unnecessary calculations for no real reason.

 

For example, suppose you had a bridge where only one person can cross at a time.

One guy will step forward, and the others would find that there's no path to the destination anymore upon recalculation. Then, whenever the guy in front moves, will you tell them to recalculate the path? There still is no path, so they wait again.

 

Once the guy reaches the end of the bridge, you tell them to recalculate and the finally one of them will get through. But that means you've potentially ran a couple dozen extra pathfinding only to realize there was no path in the end.

 

And this repeats for every event that's supposed to be moving. So if you had 5 events trying to cross the bridge, with a bridge length of 5 squares, the first guy would move across, and tell the other 4 (idle) events to recalculate for a total of 20 recalculations.

 

The second guy goes through, and tells the remaining 3 to re-calculate, for another 15 calculations.

 

I don't know how long it takes to calculate a single path once, but if you're doing more than even one of these every time you move...that's pretty bad.

 

Just wait until the coast is clear like usual.

Edited by Tsukihime

Share this post


Link to post
Share on other sites

Hm. The thing is I have seven sprites moving. Sometimes so sometimes they block each other when one has reached it's desitnation first preventing the other sprite from getting to it's destination ever.

 

 

 

And another thing it seems the path calculation doesn't take into account actors or other events. If the player stands still BEFORE the path finding the sprite still attempts to run into the player until the player moves out of the way. This could be problematic during a scene.

 

 

 

Edit: I see. What about like a script that only moves one tile at a time? If something wants to get from point A to point B it would choose the "best" adjacent tile move there than repeat until destination is reached.

 

or what about after X frames if pathfinding? == true than it recalculates. If there is no point than pathfinding? = false.

Edited by omoney

Share this post


Link to post
Share on other sites

First of all, sorry for the late reply. I'll be able to answer questions more actively from now on.

 

And another thing it seems the path calculation doesn't take into account actors or other events. If the player stands still BEFORE the path finding the sprite still attempts to run into the player until the player moves out of the way. This could be problematic during a scene.

 

Edit: I see. What about like a script that only moves one tile at a time? If something wants to get from point A to point B it would choose the "best" adjacent tile move there than repeat until destination is reached.

 

or what about after X frames if pathfinding? == true than it recalculates. If there is no point than pathfinding? = false.

Better collision checking against other events is something that's planned. It should include options to stop pathfinding after event collision. I'm still wondering whether checking for events when deciding the path is feasible, since events do have the tendency to move around while your event is doing his pathfinding.

 

Recalculating the path frequently is possible, but expect a lot of lag. Maybe when I change it to use A*, but pathfinding is quite heavy overall. I advise using pathfinding mainly for events, and especially events that are fully coordinated so you know where every event is at what time.

 

Q: How can I decrease the lag when using pathfinding?

A: Use a smaller map if possible, otherwise use the walk_to_straight method. It's less flexible, but lighter.

 

So there's no way to avoid checking the entire map for the shortest valid path?

Currently, walk_to_straight does that, sort of, but it's a bit inflexible at the moment. If I can get A* in at the next update, that algorithm checks the map for tiles that have the highest possibility of leading an event to its endpoint, so it only checks the parts of the map that are possibly relevant.

If I can't get A* functional, I'll add an optional parameter to walk_to_straight that allows you to decide how much it will check. Right now it's defaulted to 2 tiles around the event-to-endpoint rectangle.

 

This script is awesome and exactly what I've been looking for! The one issue I have with it though is that if i choose to execute path finding on several events they don't collide with each other or the player which is weird visually. I was wondering if future updates will include the option of path finding that take moving events or other path finding events or the player into considerations.

Taking moving events into consideration means the pathfinding event must know at all times where the other events on the map are, and recalculate its path every time something gets in its way. As stated above, that would require too much calculations right now.

Edited by Karanum

Share this post


Link to post
Share on other sites

I see. What about like a script that only moves one tile at a time? If something wants to get from point A to point B it would choose the "best" adjacent tile move there than repeat until destination is reached.

 

Yes, we can consider subpaths and the recursive nature of a path.

 

Suppose you've calculated your path from A to D by traveling A -> B -> C -> D, where each arrow is exactly one tile. This means you're basically moving 3 tiles to get to your destination.

 

If going from A->B->C doesn't work, because there's someone in the middle, then perhaps we can replace B with a path X = {x1, x2, ...} such that A->X->C would work.

 

If you can get to C, and C is the last step before you reach D, then you only need to figure out how to get to C (because there's no way you CAN'T get to D if you manage to get to C). Unless, of course, someone is standing at D. LOL then you're screwed.

 

And the pathfinding to go from A to C should in theory be much shorter because the distance you must travel is much, much smaller.

 

Of course, if we find that there is no path to C like on my bridge, same issue occurs, but at least you're not re-calculating the entire map.

Edited by Tsukihime

Share this post


Link to post
Share on other sites

I can't find anything in the script itself that might be causing it. I'm going to need a few things to get an idea of what's going on:

  • Open the script editor and tell me the line that's on line 180 of Game_Character
  • Do you have any other scripts installed besides this one?
  • If you're calling pathfinding from anywhere, please show me what script call you've used to call it

Share this post


Link to post
Share on other sites

When will the next version be released?  The one with...

 

- Upgrade to A* algorithm (it's faster!)

- Include diagonal movement option
- Add collision checking with events

Share this post


Link to post
Share on other sites

Could you make it so if precise spot event is supposed to move to isn't passable, it'd try to go to closest passable tile? Here's use case: I am trying to make enemies go after my player. However I don't know if spots at left, right, top and bottom will be passable when enemies will spot player, so best thing would be just to try to make script find a path to ($game_player.x,$game_player.y) and make it go to closest available spot instead.

 

There's is also bug I found regarding finding path with turned off through? (so enemies won't pass through player and other events as if they're ghosts), making it so that events can block path and even if another path exists, but is longer, event will stupidly use shorter and get stuck. I guess it's because script doesn't account for events' passability, only tilemap's. You should fix that.

 

Please fix that. I don't know shit about pathfinding (otherwise I'd write my own instead of using script), so addition mentioned in first paragraph and fix for issue mentioned in second would be welcome.

 

If you don't understand issue mentioned in second paragraph (I'm not native English speaker so it is possible that I wrote this in non-clear manner), I can make short demo presenting it.

Share this post


Link to post
Share on other sites

Not a question, but rather an amusing thing I found.

 

Using "walk_to($game_variables[x], $game_variables[y], 0)" with the x and y variables set to the x and y position of the hero, will allow an event to accurate chase the player.

 

Kudos and thanks for the script!

Share this post


Link to post
Share on other sites

@Crazy Rob- That scriptlet is actually exactly what I need.

 

@Karanum- Awesome script. If you can get it to account for other events, it will be perfect. I did have one small issue with it. If a tile is set to Passable, but a direction under Passage (4-Dir) is turned off, the pathfinding script doesn't recognize it. Occasionally an event will walk through something it shouldn't and get stuck.

It's a happened both with walk_to_straight  and walk_to_short.

Share this post


Link to post
Share on other sites

 Hello,

 

 your script is great, but I run into few errors.

1) Whenever I try to use a different method then "move_to" I get an error.

post-5862-0-51063800-1460361274_thumb.png

I tried it in autonomous movement, simple script call or in set move route, but the result was the same.

 

 

#--------------------------------------------------------------------------
# Check adjacent tiles for passability
#--------------------------------------------------------------------------
def check_adjacent_panels(x, y)
adjacent_panels = Array.new(4, false)

if y != (height - 1)
if passable?(x, y, 2) and passable?(x, y+1, 8) #Down
adjacent_panels[0] = true
end
end

if y != 0
if passable?(x, y, 8) and passable?(x, y-1, 2) #Up
adjacent_panels[2] = true
end
end

if x != (width - 1)
if passable?(x, y, 6) and passable?(x+1, y, 4) #Right
adjacent_panels[3] = true
end
end

if x != 0
if passable?(x, y, 4) and passable?(x-1, y, 6) #Left
adjacent_panels[1] = true
end
end

return adjacent_panels
end

 

 

Line 180 is in this block code as an empty line.

 

 

2a) I solved this small problem, but I want to let you know. In an autonomous event, you cannot set Event id to 0, but to the ID of the particular event. I noticed the move_to call isn't working that way.

 

2b) Using script call in set move route command requires setting "wait" to be checked otherwise event won't move.

 

3) Setting a through? parameter has no effect. The event will always walk through the player. I tried both false and true.

 

4) I use this script to make guard's patrolling paths with a help of " VX ? Trace Stealth System ? version 2.2 ? Prof. Meow Meow". It uses noise detection (investigate noise source) and I would like to know how to make the event to "abort" it's patrolling (or any other move_to call) and to start chasing the player (using another move_to call) or doing the investigation. At this moment, the event finishes its patrolling path first and then it moves to investigate the spot even if the event page was already changed to investigating page.

 

5) There seems to be an another problem. Move_to is here and there working and another moment not. I mean I set an event (player see it) to move_to a spot, that is outside of a visible screen. The event won't walk there. I set it to another spot that is as well outside of the visible screen but closer (like 2-3 tiles outside) the event walked there. I set it on a spot that's visible at the screen and the whole path as well - still no walking. I set it to another spot on the screen - suddenly the event starts walking.

 

I'm puzzled by this behaviour and any help is highly appreciated. 

 

Thanks for any answer.

 

Edit: For some reason part of my post was truncated so I re-added it.

Edit 2: I noticed I used walk_to instead move_to, my bad :-)

Edited by Eva Zumrova

Share this post


Link to post
Share on other sites

I know I'm a moron to ask this but I'm entirely used to scripts like this. I want a event to follow and kill the player upon catching them and its all in a maze. So, "walk_to_long( x, y, max_steps, id, through? )" might be the best option but how do I add it? Just paste that into the event with

"walk_to_long( x, y, max_steps, id -1, through? )"

 

or what? I never added a script in set move route before, so forgive me for a newbie question. XD

Share this post


Link to post
Share on other sites

Hmm.. By reading the instructions I think you're supposed to paste that code directly to event via 'Script...' command, not in the move route... You don't even need to put that code in the event, that you want to move ~ this can be called from another event. For example making an event, that makes another event to move. (like turning a switch, that makes enemy go towards you)

 

Also, you're supposed to fill the formula properly like this:

# walk_to_long(x, y, max_steps, id, through? )
# x = Target X coordinate of the map to go to - put a value there
# y = Target Y coordinate of the map to go to - put a value there
# max_steps = number of maximum steps - put a value there
# id = ID of the event, that you want to move. You can check event ID's by opening the event~ I believe its ID is displayed in the window's name - put a value there
# through? = should the event move through walls? - put 'true' or 'false'

# Example
walk_to_long(20, 10, 100, 5, false)

Putting this code will:

Make the event with ID 5 move to point 20,10 (x,y on map) while limiting it to maximum of 100 steps (not sure what's the purpose of this) and of course, making that event impassable (I think it (dis)allows that event to walk through walls)

 

Calling the code once (and erasing the event/turning switches) will do the thing ~ It will go to its set target position.

 

Hope that helps! :3

Share this post


Link to post
Share on other sites

Hmm.. By reading the instructions I think you're supposed to paste that code directly to event via 'Script...' command, not in the move route... You don't even need to put that code in the event, that you want to move ~ this can be called from another event. For example making an event, that makes another event to move. (like turning a switch, that makes enemy go towards you)

 

Also, you're supposed to fill the formula properly like this:

# walk_to_long(x, y, max_steps, id, through? )
# x = Target X coordinate of the map to go to - put a value there
# y = Target Y coordinate of the map to go to - put a value there
# max_steps = number of maximum steps - put a value there
# id = ID of the event, that you want to move. You can check event ID's by opening the event~ I believe its ID is displayed in the window's name - put a value there
# through? = should the event move through walls? - put 'true' or 'false'

# Example
walk_to_long(20, 10, 100, 5, false)

Putting this code will:

Make the event with ID 5 move to point 20,10 (x,y on map) while limiting it to maximum of 100 steps (not sure what's the purpose of this) and of course, making that event impassable (I think it (dis)allows that event to walk through walls)

 

Calling the code once (and erasing the event/turning switches) will do the thing ~ It will go to its set target position.

 

Hope that helps! :3

 

The only other FIM fan. ^^ Well OK, that could be simpler but let me just ask 1 more thing before I start testing it. Since the map is a maze (preset map, World Tree F1F, I edited a few walls and removed the vines as well as the weeds that stop movement) should I go and make every X and Y for the paths or would just 1 simple X and Y do?

 

Keep in mind this will be following the player, isn't ID -1 for the player?

Share this post


Link to post
Share on other sites

~

:3

 

Basically X and Y is the target position, that you want to move the event to.

So when you'll put the script call once, it will make the event move to that point while avoiding various obstacles. In other words, if the event is in the upper left corner and you'll put a script call with x/y coordinates of the bottom right corner - then the event will go through maze finding its best way to get to the bottom right corner, so theoretically, a single script call should be enough to guide the event through the maze.

It is a pathfinding script, so it's function is to calculate the fastest way from point A to point B. - so single script call to target position should be enough.

 

The ID represents the event ID that you want to move, not the one it should follow.

For example, when you'll make a new map and put 10 NPC's, then they all have their ID's displayed in their window.

 

 

luoBtml.png

 

 

Then if you want to make one of these NPC's beat the maze, then you can specify which NPC you want to move, by putting its ID.

Putting 0 as the ID will move the event, from which the script was called.

Putting -1 as the ID should move the player (something like a cutscene with move routes etc.)

 

To make the event follow the player, then you need to set the player's X and Y coordinates as the target position.

But to make it work, you'd have to make the script call be run from time to time to update the target position as the player moves.

 

You can refer to player's position by putting:

TJRQEl7.png

$game_player.x and $game_player.y will return x and y coordinates of the player.

 

So if you want to make an event, that will follow the player then you could try:

 

Making an event (enemy or whatever)

and putting this script call in the contents box (event commands):

 

walk_to_long($game_player.x, $game_player.y, 100, 0, false)

 

This will make that event go towards the player. However, if player will move, the event will not notice it and will still go towards the point, where the player was standing when the script was called. - To avoid that, you'd have to call the script each second or two ~ to keep it updated. You could try just calling it each frame, but I think that would harm the performance as it would have to calculate things each frame.

 

That's at least, how I think it works. x3

Share this post


Link to post
Share on other sites

 

~

:3

 

~

 

 

Ugh I've been messing with X and Y placement all day..in the test room I'm using for stealth. I found out its easier to do when you use 2 Xs and Ys so the killer character won't see you unless you're between those 4 numbers. However, I ran into a annoying set that has no reason to not be working..game making is a real pain. >_>

 

I'll try to test what you said tomorrow, btw I do know how to update the player's and killer's X and Y, its just fixing the walking and when/where you can be hidden or seen is a pain. XD Tomorrow I'll re-read what you said and try to make it work, but today was entirely me setting the X and Y for the stealth room.

 

At least in the maze all you gotta do is stay away from the killer, no stealth needed in that test map. Let me ask, does the speed matter when using this script? Like, the faster the event moves the greater chance of it getting stuck?

Share this post


Link to post
Share on other sites

~

Hmm... I think using a combination of proximity script and this one could work well.

I think there was a proximity script, that was toggling event pages dependable on if the event sees the player.

There, you could setup a random movement when the player would not be seen and move the enemy towards the player if seen.

Pretty confusing and stuff~ Yeah, game making isn't easy. =P

 

Try few things and see what happens! ^^

 

 

I think the speed doesn't matter - when you're putting that script call, then it instantly performs algorithms to calculate the shortest way and guides the event through the way. So I think the speed shouldn't matter ~ it sets the path instantly and then moves the event towards that point. - That being said, it shouldn't get stuck, unless the way would be blocked - there, I'm not sure how the script handles that.

Share this post


Link to post
Share on other sites

 

~

~

 

 

 

Say, when testing the stealth map I finally completed the killer's walk path and when/where you are seen from. However, it seems to only follow the path if I follow him. If I go do something else and go to find him, he's facing a bloody wall and stopped moving.

 

Wait a minute...the events that trigger the path are restarting! I just tested and the "erase event" command did not work, well if it was another page. I deleted that page added "erase event" to the end of the page that turns on another event that starts the path.

 

I swear RPG Maker has bugs. XD It is way too picky.

 

EDIT:OK this is annoying, it seems by using a event that gives you a item is what is making the killer event facing the wall without movement..so how can I fix this issue?

 

EDIT 2:I tested out the script but it keeps giving a error message, is this script for VX Ace? Btw I've been using vars to update the player x and y.

Edited by Darkness Void

Share this post


Link to post
Share on other sites

To be honest I can't test stuff, so I'm not sure how that exactly works.

 

What exactly happens? Can you post screenshots of your events?

And yes, it should be for Ace..

Share this post


Link to post
Share on other sites

~

Well that'll take a while..why not just link the demo and you can lo-right you don't test stuff..I'll just screenshot and put them in a zip later.

 


SECOND POST

Bump, here's a zip with a few screenshots.

 

http://www.mediafire.com/file/338rwq98kaqzo7f/Screenshots.zip

Edited by Rikifive
Merged Posts

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.