I wrote some code that will fix your problem.
Paste below materials above main in your scripting list.
class Game_Character #-------------------------------------------------------------------------- # * Move at Random #-------------------------------------------------------------------------- def move_random # This is important, in case the random movement breaks the game stack. @fun_random_recursion_count = 0 if @fun_random_recursion_count.nil? @fun_random_recursion_count += 1 d = 2 + rand(4) * 2 @move_succeed = passable?(@x, @y, d) if @move_succeed set_direction(d) @x = $game_map.round_x_with_direction(@x, d) @y = $game_map.round_y_with_direction(@y, d) @real_x = $game_map.x_with_direction(@x, reverse_dir(d)) @real_y = $game_map.y_with_direction(@y, reverse_dir(d)) increase_steps elsif @fun_random_recursion_count < 10 move_random end @fun_random_recursion_count -= 1 if @fun_random_recursion_count > 0 endend This isn't perfect by any means, but its actually better than the current one for moving randomly if you don't want to break your random moving path.
Random movement involves telling it to move straight, in a random direction. It does not take a direction, it just does things.
If you tell an npc to "move random" in the npc dialog, you sometimes end up with an npc STILL walking straight into walls over and over, because the code is tied to a "move forward" call in random intervals as well. I can however fix this as well, because the "Game_Event" class also contains a series of directional movement controllers, a hierarchy to dictate default movements you configure using the game making software.
Code:
# Replace Thisclass Game_Event < Game_Character #-------------------------------------------------------------------------- # * Move Type : Random #-------------------------------------------------------------------------- def move_type_random case rand(6) when 0..1; move_random when 2..4; move_forward when 5; @stop_count = 0 end endend# With This if you want the "forward" directional movement to stop.class Game_Event < Game_Character #-------------------------------------------------------------------------- # * Move Type : Random #-------------------------------------------------------------------------- def move_type_random case rand(6) when 0..4; move_random when 5; @stop_count = 0 end endend