Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

8 directional Pathfinding

I have Near_Fantastica's Pathfinding script. The only problem is that it only moves the character in four directions. I also have my own script which allows for facing in 8 directions and have tried editing Near's script to allow 8 directional movement. My only problem is when the script is called, the character moves as it should, except it faces seemingly random directions as it moves, not always the direction in which it is moving.

Here are the two versions of the script.

Code:
#==============================================================================
#  â–  Path Finding
#==============================================================================
# Near Fantastica
# Version 1
# 29.11.05
#==============================================================================
# Lets the Player or Event draw a path from an desonation to the source. This
# method is very fast and because the palthfinding is imbeded into the Game
# Character the pathfinding can be inturputed or redrawn at any time. 
#==============================================================================
# Player :: $game_player.find_path(x,y)
# Event Script Call :: self.event.find_path(x,y)
# Event Movement Script Call :: self.find_path(x,y)
#==============================================================================

#--------------------------------------------------------------------------
# * SDK Log Script
#--------------------------------------------------------------------------
SDK.log("Path Finding", "Near Fantastica", 1, "29.11.05")

#--------------------------------------------------------------------------
# * Begin SDK Enable Test
#--------------------------------------------------------------------------
if SDK.state("Path Finding") == true
  class Game_Character
    #--------------------------------------------------------------------------
    alias nf_pf_game_character_initialize initialize
    alias nf_pf_game_character_update update
    #--------------------------------------------------------------------------
    attr_accessor :map
    attr_accessor :runpath
    #--------------------------------------------------------------------------
    def initialize
      nf_pf_game_character_initialize
      @map = nil
      @runpath = false
    end
    #--------------------------------------------------------------------------
    def update
      run_path if @runpath == true
      nf_pf_game_character_update
    end
    #--------------------------------------------------------------------------
    def run_path
      return if moving?
      step = @map[@x,@y]
      if step == 1
        @map = nil
        @runpath = false
        return
      end
      dir = rand(2)
      case dir
      when 0
        move_right if @map[@x+1,@y] == step - 1 and step != 0
        move_down if @map[@x,@y+1] == step - 1 and step != 0
        move_left if @map[@x-1,@y] == step -1 and step != 0
        move_up if @map[@x,@y-1] == step - 1 and step != 0
      when 1
        move_up if @map[@x,@y-1] == step - 1 and step != 0
        move_left if @map[@x-1,@y] == step -1 and step != 0
        move_down if @map[@x,@y+1] == step - 1 and step != 0
        move_right if @map[@x+1,@y] == step - 1 and step != 0
      end
    end
    #--------------------------------------------------------------------------
    def find_path(x,y)
      sx, sy = @x, @y
      result = setup_map(sx,sy,x,y)
      @runpath = result[0]
      @map = result[1]
      @map[sx,sy] = result[2] if result[2] != nil
    end
    #--------------------------------------------------------------------------
    def clear_path
      @map = nil
      @runpath = false
    end
    #--------------------------------------------------------------------------
    def setup_map(sx,sy,ex,ey)
      map = Table.new($game_map.width, $game_map.height)
      map[ex,ey] = 1
      old_positions = []
      new_positions = []
      old_positions.push([ex, ey])
      depth = 2
      depth.upto(100){|step|
        loop do
          break if old_positions[0] == nil
          x,y = old_positions.shift
          return [true, map, step] if x == sx and y+1 == sy
          if $game_player.passable?(x, y, 2) and map[x,y + 1] == 0
            map[x,y + 1] = step
            new_positions.push([x,y + 1])
          end
          return [true, map, step] if x-1 == sx and y == sy
          if $game_player.passable?(x, y, 4) and map[x - 1,y] == 0
            map[x - 1,y] = step
            new_positions.push([x - 1,y])
          end
          return [true, map, step] if x+1 == sx and y == sy
          if $game_player.passable?(x, y, 6) and map[x + 1,y] == 0
            map[x + 1,y] = step
            new_positions.push([x + 1,y])
          end
          return [true, map, step] if x == sx and y-1 == sy
          if $game_player.passable?(x, y, 8) and map[x,y - 1] == 0
            map[x,y - 1] = step
            new_positions.push([x,y - 1])
          end
        end
        old_positions = new_positions
        new_positions = []
      }
      return [false, nil, nil]
    end
  end
  
  class Game_Map
    #--------------------------------------------------------------------------
    alias pf_game_map_setup setup
    #--------------------------------------------------------------------------
    def setup(map_id)
      pf_game_map_setup(map_id)
      $game_player.clear_path
    end
  end
  
  class Game_Player
    #--------------------------------------------------------------------------
    alias pf_game_player_update_player_movement update_player_movement
    #--------------------------------------------------------------------------
    def update_player_movement
      $game_player.clear_path if Input.dir4 != 0
      pf_game_player_update_player_movement
    end
  end
  
  class Interpreter
    #--------------------------------------------------------------------------
    def event
      return $game_map.events[@event_id]
    end
  end
  
#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end
Code:
#==============================================================================
#  â–  Path Finding
#==============================================================================
# Near Fantastica *edited by Draycos Goldaryn
# Version 1       *1.5 beta
# 29.11.05        *26.02.07
#==============================================================================
# Lets the Player or Event draw a path from an desonation to the source. This
# method is very fast and because the palthfinding is imbeded into the Game
# Character the pathfinding can be inturputed or redrawn at any time. 
#==============================================================================
# Player :: $game_player.find_path(x,y)
# Event Script Call :: self.event.find_path(x,y)
# Event Movement Script Call :: self.find_path(x,y)
#==============================================================================

#--------------------------------------------------------------------------
# * SDK Log Script
#--------------------------------------------------------------------------
SDK.log("Path Finding", "Near Fantastica", 1, "29.11.05")

#--------------------------------------------------------------------------
# * Begin SDK Enable Test
#--------------------------------------------------------------------------
if SDK.state("Path Finding") == true
  class Game_Character
    #--------------------------------------------------------------------------
    alias nf_pf_game_character_initialize initialize
    alias nf_pf_game_character_update update
    #--------------------------------------------------------------------------
    attr_accessor :map
    attr_accessor :runpath
    #--------------------------------------------------------------------------
    def initialize
      nf_pf_game_character_initialize
      @map = nil
      @runpath = false
    end
    #--------------------------------------------------------------------------
    def update
      run_path if @runpath == true
      nf_pf_game_character_update
    end
    #--------------------------------------------------------------------------
    def run_path
      return if moving?
      step = @map[@x,@y]
      if step == 1
        @map = nil
        @runpath = false
        return
      end
      dir = rand(4)
      case dir
      when 0
        move_upper_right if @map[@x+1,@y-1] == step - 1 and step != 0
        move_lower_right if @map[@x+1,@y+1] == step - 1 and step != 0
        move_lower_left if @map[@x-1,@y+1] == step - 1 and step != 0
        move_upper_left if @map[@x-1,@y-1] == step - 1 and step != 0
      when 1
        move_down if @map[@x,@y+1] == step - 1 and step != 0
        move_right if @map[@x+1,@y] == step - 1 and step != 0
        move_left if @map[@x-1,@y] == step -1 and step != 0
        move_up if @map[@x,@y-1] == step - 1 and step != 0
      when 2
        move_upper_left if @map[@x-1,@y-1] == step - 1 and step != 0
        move_lower_left if @map[@x-1,@y+1] == step - 1 and step != 0
        move_lower_right if @map[@x+1,@y+1] == step - 1 and step != 0
        move_upper_right if @map[@x+1,@y-1] == step - 1 and step != 0
      when 3
        move_up if @map[@x,@y-1] == step - 1 and step != 0
        move_left if @map[@x-1,@y] == step -1 and step != 0
        move_down if @map[@x,@y+1] == step - 1 and step != 0
        move_right if @map[@x+1,@y] == step - 1 and step != 0
      end
    end
    #--------------------------------------------------------------------------
    def find_path(x,y)
      sx, sy = @x, @y
      result = setup_map(sx,sy,x,y)
      @runpath = result[0]
      @map = result[1]
      @map[sx,sy] = result[2] if result[2] != nil
    end
    #--------------------------------------------------------------------------
    def clear_path
      @map = nil
      @runpath = false
    end
    #--------------------------------------------------------------------------
    def setup_map(sx,sy,ex,ey)
      map = Table.new($game_map.width, $game_map.height)
      map[ex,ey] = 1
      old_positions = []
      new_positions = []
      old_positions.push([ex, ey])
      depth = 2
      depth.upto(100){|step|
        loop do
          break if old_positions[0] == nil
          x,y = old_positions.shift
          # lower left
          return [true, map, step] if x-1 == sx and y+1 == sy
          if (($game_player.passable?(@x, @y, 2) and $game_player.passable?(@x, @y + 1, 4)) or
              ($game_player.passable?(@x, @y, 4) and $game_player.passable?(@x - 1, @y, 2))) and map[x - 1,y + 1] == 0
            map[x - 1,y + 1] = step
            new_positions.push([x - 1,y + 1])
          end
          # down
          return [true, map, step] if x == sx and y+1 == sy
          if $game_player.passable?(x, y, 2) and map[x,y + 1] == 0
            map[x,y + 1] = step
            new_positions.push([x,y + 1])
          end
          # lower right
          return [true, map, step] if x+1 == sx and y+1 == sy
          if (($game_player.passable?(@x, @y, 2) and $game_player.passable?(@x, @y + 1, 6)) or
              ($game_player.passable?(@x, @y, 6) and $game_player.passable?(@x + 1, @y, 2))) and map[x + 1,y + 1] == 0
            map[x + 1,y + 1] = step
            new_positions.push([x + 1,y + 1])
          end
          # left
          return [true, map, step] if x-1 == sx and y == sy
          if $game_player.passable?(x, y, 4) and map[x - 1,y] == 0
            map[x - 1,y] = step
            new_positions.push([x - 1,y])
          end
          # right
          return [true, map, step] if x+1 == sx and y == sy
          if $game_player.passable?(x, y, 6) and map[x + 1,y] == 0
            map[x + 1,y] = step
            new_positions.push([x + 1,y])
          end
          # upper left
          return [true, map, step] if x-1 == sx and y-1 == sy
          if (($game_player.passable?(@x, @y, 8) and $game_player.passable?(@x, @y - 1, 4)) or
              ($game_player.passable?(@x, @y, 4) and $game_player.passable?(@x - 1, @y, 8))) and map[x - 1,y - 1] == 0
            map[x - 1,y - 1] = step
            new_positions.push([x - 1,y - 1])
          end
          # up
          return [true, map, step] if x == sx and y-1 == sy
          if $game_player.passable?(x, y, 8) and map[x,y - 1] == 0
            map[x,y - 1] = step
            new_positions.push([x,y - 1])
          end
          # upper right
          return [true, map, step] if x+1 == sx and y-1 == sy
          if (($game_player.passable?(@x, @y, 2) and $game_player.passable?(@x, @y - 1, 6)) or
              ($game_player.passable?(@x, @y, 6) and $game_player.passable?(@x + 1, @y, 2))) and map[x + 1,y - 1] == 0
            map[x + 1,y - 1] = step
            new_positions.push([x + 1,y - 1])
          end
        end
        old_positions = new_positions
        new_positions = []
      }
      return [false, nil, nil]
    end
  end
  
  class Game_Map
    #--------------------------------------------------------------------------
    alias pf_game_map_setup setup
    #--------------------------------------------------------------------------
    def setup(map_id)
      pf_game_map_setup(map_id)
      $game_player.clear_path
    end
  end
  
  class Game_Player
    #--------------------------------------------------------------------------
    alias pf_game_player_update_player_movement update_player_movement
    #--------------------------------------------------------------------------
    def update_player_movement
      $game_player.clear_path if Input.dir8 != 0
      pf_game_player_update_player_movement
    end
  end
  
  class Interpreter
    #--------------------------------------------------------------------------
    def event
      return $game_map.events[@event_id]
    end
  end
  
#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end

Can anyone help me?
 
Bump bumpity bump bump bumpity Here are the other scripts that aslo affect this:

Code:
#==============================================================================
# â–  Advanced 8-Directional Movement
#------------------------------------------------------------------------------
# Draycos Goldaryn
# Version 2
# 14.03.2007
#------------------------------------------------------------------------------
# This script allows for a more extensive 8 directional movement system than
# comes default with RMXP. It also improves the diagonal sprite movements.
# This script also affects events as well as the player. It also has the option
# to toggle between four different methods of movement:
#   Default 8-directional Movement
#     Using the arrow keys, the player can move in all eight directions.
#   Point and Click Movement
#     Using Near_Fantastica's Mouse and Keyboard Modules along with his
#     Pathfinding Script, the player may move his character with the mouse.
#   Axial Movement
#     Best for use with vehicles, the player turns 45° using the left and right
#     arrows and move forward or backward using the up or down arrow 
#     respectively.
#   Movement Control using Numpad
#     The player uses the numpad to move in all 8 directions according to the
#     following diagram:
#         \  |  /
#          7 8 9 
#         -4   6-
#          1 2 3
#         /  |  \
# Also, character sprites now must include 8 poses: one for each direction, in
# the following order:
#   Lower Left
#   Down
#   Lower Right
#   Left
#   Right
#   Upper Left
#   Up
#   Upper Right
#------------------------------------------------------------------------------
# Syntax:
#   To toggle the different methods of movement on, call the following scripts:
#     Default 8-directional movement  : $game_system.default_movement = true
#     Point and Click movement        : $game_system.mouse_movement = true
#     Axial Movement                  : $game_system.axial_movement = true
#     Movement Control using Numpad   : $game_system.numpad_movement = true
#==============================================================================

class Game_System
  attr_accessor :default_movement
  attr_accessor :mouse_movement
  attr_accessor :axial_movement
  attr_accessor :numpad_movement
  alias toggle_movement_init initialize
  def initialize
    toggle_movement_init
    @default_movement = true
    @mouse_movement = false
    @axial_movement = false
    @numpad_movement = false
  end
end

class Game_Character
  #--------------------------------------------------------------------------
  # * Move Lower Left
  #--------------------------------------------------------------------------
  def move_lower_left(turn_enabled = true)
    # Turn up
    if turn_enabled
      turn_lower_left
    end
    # When a down to left or a left to down course is passable
    if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
       (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
      # Update coordinates
      @x -= 1
      @y += 1
      # Increase steps
      increase_steps
    # If impassable
    else
      # Determine if touch event is triggered
      check_event_trigger_touch(@x-1, @y+1)
    end
  end
  #--------------------------------------------------------------------------
  # * Move Lower Right
  #--------------------------------------------------------------------------
  def move_lower_right(turn_enabled = true)
    # Turn up
    if turn_enabled
      turn_lower_right
    end
    # When a down to right or a right to down course is passable
    if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
       (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
      # Update coordinates
      @x += 1
      @y += 1
      # Increase steps
      increase_steps
    # If impassable
    else
      # Determine if touch event is triggered
      check_event_trigger_touch(@x+1, @y+1)
    end
  end
  #--------------------------------------------------------------------------
  # * Move Upper Left
  #--------------------------------------------------------------------------
  def move_upper_left(turn_enabled = true)
    # Turn up
    if turn_enabled
      turn_upper_left
    end
    # When an up to left or a left to up course is passable
    if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
       (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
      # Update coordinates
      @x -= 1
      @y -= 1
      # Increase steps
      increase_steps
    # If impassable
    else
      # Determine if touch event is triggered
      check_event_trigger_touch(@x-1, @y-1)
    end
  end
  #--------------------------------------------------------------------------
  # * Move Upper Right
  #--------------------------------------------------------------------------
  def move_upper_right(turn_enabled = true)
    # Turn up
    if turn_enabled
      turn_upper_right
    end
    # When an up to right or a right to up course is passable
    if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
       (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
      # Update coordinates
      @x += 1
      @y -= 1
      # Increase steps
      increase_steps
    # If impassable
    else
      # Determine if touch event is triggered
      check_event_trigger_touch(@x+1, @y-1)
    end
  end
  #--------------------------------------------------------------------------
  # * Move at Random
  #--------------------------------------------------------------------------
  def move_random
    case rand(8)
    when 0  # Move down
      move_down(false)
    when 1  # Move left
      move_left(false)
    when 2  # Move right
      move_right(false)
    when 3  # Move up
      move_up(false)
    when 4
      move_lower_left(false)
    when 5
      move_lower_right(false)
    when 6
      move_upper_left(false)
    when 7
      move_upper_right(false)
    end
  end
  #--------------------------------------------------------------------------
  # * 1 Step Forward
  #--------------------------------------------------------------------------
  def move_forward
    case @direction
    when 2
      move_down(false)
    when 4
      move_left(false)
    when 6
      move_right(false)
    when 8
      move_up(false)
    when 1 #lower left
      move_lower_left(false)
    when 3 #lower right
      move_lower_right(false)
    when 7 #upper left
      move_upper_left(false)
    when 9 #upper right
      move_upper_right(false)
    end
  end
  #--------------------------------------------------------------------------
  # * 1 Step Backward
  #--------------------------------------------------------------------------
  def move_backward
    # Remember direction fix situation
    last_direction_fix = @direction_fix
    # Force directino fix
    @direction_fix = true
    # Branch by direction
    case @direction
    when 2  # Down
      move_up(false)
    when 4  # Left
      move_right(false)
    when 6  # Right
      move_left(false)
    when 8  # Up
      move_down(false)
    when 1 #lower left
      move_upper_right(false)
    when 3 #lower right
      move_upper_left(false)
    when 7 #upper left
      move_lower_right(false)
    when 9 #upper right
      move_lower_left(false)
    end
    # Return direction fix situation back to normal
    @direction_fix = last_direction_fix
  end
  #--------------------------------------------------------------------------
  # * Turn Lower Left
  #--------------------------------------------------------------------------
  def turn_lower_left
    unless @direction_fix
      @direction = 1
      @stop_count = 0
    end
  end
  #--------------------------------------------------------------------------
  # * Turn Lower Right
  #--------------------------------------------------------------------------
  def turn_lower_right
    unless @direction_fix
      @direction = 3
      @stop_count = 0
    end
  end
  #--------------------------------------------------------------------------
  # * Turn Upper Left
  #--------------------------------------------------------------------------
  def turn_upper_left
    unless @direction_fix
      @direction = 7
      @stop_count = 0
    end
  end
  #--------------------------------------------------------------------------
  # * Turn Upper Right
  #--------------------------------------------------------------------------
  def turn_upper_right
    unless @direction_fix
      @direction = 9
      @stop_count = 0
    end
  end
  #--------------------------------------------------------------------------
  # * Turn 90° Right
  #--------------------------------------------------------------------------
  def turn_right_90
    case @direction
    when 2
      turn_left
    when 4
      turn_up
    when 6
      turn_down
    when 8
      turn_right
    when 1
      turn_upper_left
    when 3
      turn_lower_left
    when 7
      turn_upper_right
    when 9
      turn_lower_right
    end
  end
  #--------------------------------------------------------------------------
  # * Turn 90° Left
  #--------------------------------------------------------------------------
  def turn_left_90
    case @direction
    when 2
      turn_right
    when 4
      turn_down
    when 6
      turn_up
    when 8
      turn_left
    when 1
      turn_upper_right
    when 3
      turn_upper_left
    when 7
      turn_lower_right
    when 9
      turn_lower_left
    end
  end
  #--------------------------------------------------------------------------
  # * Turn 180°
  #--------------------------------------------------------------------------
  def turn_180
    case @direction
    when 2
      turn_up
    when 4
      turn_right
    when 6
      turn_left
    when 8
      turn_down
    when 1
      turn_upper_left
    when 3
      turn_lower_left
    when 7
      turn_upper_right
    when 9
      turn_lower_right
    end
  end
  #--------------------------------------------------------------------------
  # * Turn 90° Right or Left
  #--------------------------------------------------------------------------
  def turn_right_or_left_90
    if rand(2) == 0
      turn_right_90
    else
      turn_left_90
    end
  end
  #--------------------------------------------------------------------------
  # * Turn at Random
  #--------------------------------------------------------------------------
  def turn_random
    case rand(4)
    when 0
      turn_up
    when 1
      turn_right
    when 2
      turn_left
    when 3
      turn_down
    when 4
      turn_lower_left
    when 5
      turn_lower_right
    when 6
      turn_upper_left
    when 7
      turn_upper_right
    end
  end
  #--------------------------------------------------------------------------
  # * Turn 45° Right
  #--------------------------------------------------------------------------
  def turn_right_45
    case @direction
    when 2
      turn_lower_left
    when 4
      turn_upper_left
    when 6
      turn_lower_right
    when 8
      turn_upper_right
    when 1
      turn_left
    when 3
      turn_down
    when 7
      turn_up
    when 9
      turn_right
    end
  end
  #--------------------------------------------------------------------------
  # * Turn 45° Left
  #--------------------------------------------------------------------------
  def turn_left_45
    case @direction
    when 2
      turn_lower_right
    when 4
      turn_lower_left
    when 6
      turn_upper_right
    when 8
      turn_upper_left
    when 1
      turn_down
    when 3
      turn_right
    when 7
      turn_left
    when 9
      turn_up
    end
  end
  #--------------------------------------------------------------------------
  # * Turn 45° Right or Left
  #--------------------------------------------------------------------------
  def turn_right_or_left_45
    if rand(2) == 0
      turn_right_45
    else
      turn_left_45
    end
  end
end


class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  # * Front Event Starting Determinant
  #--------------------------------------------------------------------------
  def check_event_trigger_there(triggers)
    result = false
    # If event is running
    if $game_system.map_interpreter.running?
      return result
    end
    # Calculate front event coordinates
    new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : @direction == 1 ? -1 : @direction == 3 ? +1 : @direction == 7 ? -1 : @direction == 9 ? +1 : 0)
    new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : @direction == 1 ? +1 : @direction == 3 ? +1 : @direction == 7 ? -1 : @direction == 9 ? -1 : 0)
    # All event loops
    for event in $game_map.events.values
      # If event coordinates and triggers are consistent
      if event.x == new_x and event.y == new_y and
         triggers.include?(event.trigger)
        # If starting determinant is front event (other than jumping)
        if not event.jumping? and not event.over_trigger?
          event.start
          result = true
        end
      end
    end
    # If fitting event is not found
    if result == false
      # If front tile is a counter
      if $game_map.counter?(new_x, new_y)
        # Calculate 1 tile inside coordinates
        new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : @direction == 1 ? -1 : @direction == 3 ? +1 : @direction == 7 ? -1 : @direction == 9 ? +1 : 0)
        new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : @direction == 1 ? +1 : @direction == 3 ? +1 : @direction == 7 ? -1 : @direction == 9 ? -1 : 0)
        # All event loops
        for event in $game_map.events.values
          # If event coordinates and triggers are consistent
          if event.x == new_x and event.y == new_y and
             triggers.include?(event.trigger)
            # If starting determinant is front event (other than jumping)
            if not event.jumping? and not event.over_trigger?
              event.start
              result = true
            end
          end
        end
      end
    end
    return result
  end

  @wait_count = 0
    def update
    # Remember whether or not moving in local variables
    last_moving = moving?
    # If moving, event running, move route forcing, and message window
    # display are all not occurring
    Keyboard.update
    Mouse.update
    if @wait_count > 0
      @wait_count -= 1
      return
    end
    unless moving? or $game_system.map_interpreter.running? or
           @move_route_forcing or $game_temp.message_window_showing
      # Move player using the Mouse
      if $game_system.mouse_movement == true
        if Keyboard.pressed?(Keyboard::Mouse_Left) 
          x =  Mouse.grid[0] #(Mouse.pos[0] / 32)+($game_map.display_x / 4)/32
          y =  Mouse.grid[1] #(Mouse.pos[1] / 32)+($game_map.display_y / 4)/32
          # checks to see if an event occupies the map tile
          while $game_map.check_event(x,y).is_a?(Numeric)
            return #does nothing | can edit this later to do something else
          end
          $game_player.find_path(x,y) # moves the player if there is no event
        end
      end
      # Move player with the default method
      if $game_system.default_movement == true
        case Input.dir8
        when 2
          move_down
        when 4
          move_left
        when 6
          move_right
        when 8
          move_up
        when 1
          move_lower_left
        when 3
          move_lower_right
        when 7
          move_upper_left
        when 9
          move_upper_right
        end
      end
      # Move player using the numpad
      if $game_system.numpad_movement == true
        if Keyboard.pressed?(Keyboard::Numberpad[1])
          p "move_lower_left"
        end
        if Keyboard.pressed?(Keyboard::Numberpad[2])
          p "move_down"
        end
        if Keyboard.pressed?(Keyboard::Numberpad[3])
          p "move_lower_right"
        end
        if Keyboard.pressed?(Keyboard::Numberpad[4])
          p "move_left"
        end
        if Keyboard.pressed?(Keyboard::Numberpad[6])
          p "move_right"
        end
        if Keyboard.pressed?(Keyboard::Numberpad[7])
          p "move_upper_left"
        end
        if Keyboard.pressed?(Keyboard::Numberpad[8])
          p "move_up"
        end
        if Keyboard.pressed?(Keyboard::Numberpad[9])
          p "move_upper_right"
        end
      end      
      # Turn player using left/right and forward/backward using up/down
      if $game_system.axial_movement == true
        case Input.dir4
        when 2
          move_backward
        when 4
          turn_left_45
          @wait_count = 5
        when 6
          turn_right_45
          @wait_count = 5
        when 8
          move_forward
        end
      end
    end
    # Remember coordinates in local variables
    last_real_x = @real_x
    last_real_y = @real_y
    super
    # If character moves down and is positioned lower than the center
    # of the screen
    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
      # Scroll map down
      $game_map.scroll_down(@real_y - last_real_y)
    end
    # If character moves left and is positioned more left on-screen than
    # center
    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
      # Scroll map left
      $game_map.scroll_left(last_real_x - @real_x)
    end
    # If character moves right and is positioned more right on-screen than
    # center
    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
      # Scroll map right
      $game_map.scroll_right(@real_x - last_real_x)
    end
    # If character moves up and is positioned higher than the center
    # of the screen
    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
      # Scroll map up
      $game_map.scroll_up(last_real_y - @real_y)
    end
    # If not moving
    unless moving?
      # If player was moving last time
      if last_moving
        # Event determinant is via touch of same position event
        result = check_event_trigger_here([1,2])
        # If event which started does not exist
        if result == false
          # Disregard if debug mode is ON and ctrl key was pressed
          unless $DEBUG and Input.press?(Input::CTRL)
            # Encounter countdown
            if @encounter_count > 0
              @encounter_count -= 1
            end
          end
        end
      end
      # If C button was pressed
      if Input.trigger?(Input::C)
        # Same position and front event determinant
        check_event_trigger_here([0])
        check_event_trigger_there([0,1,2])
      end
    end
  end
end

class Sprite_Character < RPG::Sprite
  def update
    super
    # If tile ID, file name, or hue are different from current ones
    if @tile_id != @character.tile_id or
       @character_name != @character.character_name or
       @character_hue != @character.character_hue
      # Remember tile ID, file name, and hue
      @tile_id = @character.tile_id
      @character_name = @character.character_name
      @character_hue = @character.character_hue
      # If tile ID value is valid
      if @tile_id >= 384
        self.bitmap = RPG::Cache.tile($game_map.tileset_name,
          @tile_id, @character.character_hue)
        self.src_rect.set(0, 0, 32, 32)
        self.ox = 16
        self.oy = 32
      # If tile ID value is invalid
      else
        self.bitmap = RPG::Cache.character(@character.character_name,
          @character.character_hue)
        @cw = bitmap.width / 4
        @ch = bitmap.height / 8
        self.ox = @cw / 2
        self.oy = @ch
      end
    end
    # Set visible situation
    self.visible = (not @character.transparent)
    # If graphic is character
    if @tile_id == 0
      # Set rectangular transfer
      sx = @character.pattern * @cw
      if @character.direction >= 6
        sy = (@character.direction - 2 ) * @ch
      else
        sy = (@character.direction - 1 ) * @ch
      end
      self.src_rect.set(sx, sy, @cw, @ch)
    end
    # Set sprite coordinates
    self.x = @character.screen_x
    self.y = @character.screen_y
    self.z = @character.screen_z(@ch)
    # Set opacity level, blend method, and bush depth
    self.opacity = @character.opacity
    self.blend_type = @character.blend_type
    self.bush_depth = @character.bush_depth
    # Animation
    if @character.animation_id != 0
      animation = $data_animations[@character.animation_id]
      animation(animation, true)
      @character.animation_id = 0
    end
  end
end
Code:
#==============================================================================
# ** Keyboard Input Module
#==============================================================================
# Near Fantastica # Edited by Draycos Goldaryn
# Version 5       # Version 6
# 29.11.05        # 15.03.07
#==============================================================================
# The Keyboard Input Module is designed to function as the default Input module
# dose. It is better then other methods keyboard input because as a key is 
# tested it is not removed form the list. so you can test the same key multiple
# times the same loop.
#
# Keys added by Draycos:
#   Middle Mouse Button
#   Pause
#   Caps Lock
#   Page Up
#   Page Down
#   End
#   Home
#   Left
#   Up
#   Right
#   Down
#   Print Screen
#   Insert
#   Delete
#   Corrected numberpad values
#   Numberpad["*"]
#   Numberpad["+"]
#   Numberpad["-"]
#   Numberpad["."]
#   Numberpad["/"]
#   Left Windows Button
#   Right Windows Buttons
#   Application Button (The one that right clicks for you)
#   Num Lock
#   Scroll Lock 
#   Left Shift
#   Right Shift
#   Left Ctrl
#   Right Ctrl
#   Left Alt
#   Right Alt
#   Frontslash ( / )
#   Tilde
#   Backslash ( \ )
#   Quote 
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log("Keyboard Input", "Near Fantastica -- Draycos Goldaryn", 6, "15.03.07")

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.state("Keyboard Input") == true
  
  module Keyboard
    #--------------------------------------------------------------------------
    @keys = []
    @pressed = []
    Mouse_Left = 1
    Mouse_Right = 2
    Mouse_Middle = 4
    Back= 8
    Tab = 9
    Enter = 13
    Shift = 16
    Ctrl = 17
    Alt = 18
    Pause = 19
    Caps_Lock = 20
    Esc = 27
    Space = 32
    PgUp = 33
    PgDn = 34
    End = 35
    Home = 36
    Left = 37
    Up = 38
    Right = 39
    Down = 40
    Print_Screen = 44
    Insert = 45
    Delete = 46
    Numberkeys = {}
    Numberkeys[0] = 48
    Numberkeys[1] = 49
    Numberkeys[2] = 50
    Numberkeys[3] = 51
    Numberkeys[4] = 52
    Numberkeys[5] = 53
    Numberkeys[6] = 54
    Numberkeys[7] = 55
    Numberkeys[8] = 56
    Numberkeys[9] = 57
    Numberpad = {}
    Numberpad[0] = 96
    Numberpad[1] = 97
    Numberpad[2] = 98
    Numberpad[3] = 99
    Numberpad[4] = 100
    Numberpad[5] = 101
    Numberpad[6] = 102
    Numberpad[7] = 103
    Numberpad[8] = 104
    Numberpad[9] = 105
    Numberpad["*"] = 106
    Numberpad["+"] = 107
    Numberpad["-"] = 109
    Numberpad["."] = 110
    Numberpad["/"] = 111
    Letters = {}
    Letters["A"] = 65
    Letters["B"] = 66
    Letters["C"] = 67
    Letters["D"] = 68
    Letters["E"] = 69
    Letters["F"] = 70
    Letters["G"] = 71
    Letters["H"] = 72
    Letters["I"] = 73
    Letters["J"] = 74
    Letters["K"] = 75
    Letters["L"] = 76
    Letters["M"] = 77
    Letters["N"] = 78
    Letters["O"] = 79
    Letters["P"] = 80
    Letters["Q"] = 81
    Letters["R"] = 82
    Letters["S"] = 83
    Letters["T"] = 84
    Letters["U"] = 85
    Letters["V"] = 86
    Letters["W"] = 87
    Letters["X"] = 88
    Letters["Y"] = 89
    Letters["Z"] = 90
    L_Windows = 91
    R_Windows = 92
    Application = 93
    Fkeys = {}
    Fkeys[1] = 112
    Fkeys[2] = 113
    Fkeys[3] = 114
    Fkeys[4] = 115
    Fkeys[5] = 116
    Fkeys[6] = 117
    Fkeys[7] = 118
    Fkeys[8] = 119
    Fkeys[9] = 120
    Fkeys[10] = 121
    Fkeys[11] = 122
    Fkeys[12] = 123
    NumLock = 144
    Scroll_Lock = 145
    L_Shift = 160
    R_Shift = 161
    L_Ctrl = 162
    R_Ctrl = 163
    L_Alt = 164
    R_Alt = 165
    Collon = 186
    Equal = 187
    Comma = 188
    Underscore = 189
    Dot = 190
    Frontslash = 191
    Tilde = 192
    Lb = 219
    Backslash = 220
    Rb = 221
    Quote = 222
    
    State = Win32API.new("user32","GetKeyState",['i'],'i')
    Key = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
    #--------------------------------------------------------------------------  
    def Keyboard.getstate(key)
      return true unless State.call(key).between?(0, 1)
      return false
    end
    #--------------------------------------------------------------------------
    def Keyboard.testkey(key)
      Key.call(key) & 0x01 == 1
    end
    #--------------------------------------------------------------------------
    def Keyboard.update
      @keys = []
      @keys.push(Keyboard::Mouse_Left) if Keyboard.testkey(Keyboard::Mouse_Left)
      @keys.push(Keyboard::Mouse_Right) if Keyboard.testkey(Keyboard::Mouse_Right)
      @keys.push(Keyboard::Mouse_Middle) if Keyboard.testkey(Keyboard::Mouse_Middle)
      @keys.push(Keyboard::Back) if Keyboard.testkey(Keyboard::Back)
      @keys.push(Keyboard::Tab) if Keyboard.testkey(Keyboard::Tab)
      @keys.push(Keyboard::Enter) if Keyboard.testkey(Keyboard::Enter)
      @keys.push(Keyboard::Shift) if Keyboard.testkey(Keyboard::Shift)
      @keys.push(Keyboard::Ctrl) if Keyboard.testkey(Keyboard::Ctrl)
      @keys.push(Keyboard::Alt) if Keyboard.testkey(Keyboard::Alt)
      @keys.push(Keyboard::Pause) if Keyboard.testkey(Keyboard::Pause)
      @keys.push(Keyboard::Caps_Lock) if Keyboard.testkey(Keyboard::Caps_Lock)
      @keys.push(Keyboard::Esc) if Keyboard.testkey(Keyboard::Esc)
      @keys.push(Keyboard::Space) if Keyboard.testkey(Keyboard::Space)
      @keys.push(Keyboard::PgUp) if Keyboard.testkey(Keyboard::PgUp)
      @keys.push(Keyboard::PgDn) if Keyboard.testkey(Keyboard::PgDn)
      @keys.push(Keyboard::End) if Keyboard.testkey(Keyboard::End)
      @keys.push(Keyboard::Home) if Keyboard.testkey(Keyboard::Home)
      @keys.push(Keyboard::Left) if Keyboard.testkey(Keyboard::Left)
      @keys.push(Keyboard::Up) if Keyboard.testkey(Keyboard::Up)
      @keys.push(Keyboard::Right) if Keyboard.testkey(Keyboard::Right)
      @keys.push(Keyboard::Down) if Keyboard.testkey(Keyboard::Down)
      @keys.push(Keyboard::Print_Screen) if Keyboard.testkey(Keyboard::Print_Screen)
      @keys.push(Keyboard::Insert) if Keyboard.testkey(Keyboard::Insert)
      @keys.push(Keyboard::Delete) if Keyboard.testkey(Keyboard::Delete)
      for key in Keyboard::Numberkeys.values
        @keys.push(key) if Keyboard.testkey(key)
      end
      for key in Keyboard::Numberpad.values
        @keys.push(key) if Keyboard.testkey(key)
      end
      for key in Keyboard::Letters.values
        @keys.push(key) if Keyboard.testkey(key)
      end
      @keys.push(Keyboard::L_Windows) if Keyboard.testkey(Keyboard::L_Windows)
      @keys.push(Keyboard::R_Windows) if Keyboard.testkey(Keyboard::R_Windows)
      @keys.push(Keyboard::Application) if Keyboard.testkey(Keyboard::Application)
      for key in Keyboard::Fkeys.values
        @keys.push(key) if Keyboard.testkey(key)
      end
      @keys.push(Keyboard::NumLock) if Keyboard.testkey(Keyboard::NumLock)
      @keys.push(Keyboard::Scroll_Lock) if Keyboard.testkey(Keyboard::Scroll_Lock)
      @keys.push(Keyboard::L_Shift) if Keyboard.testkey(Keyboard::L_Shift)
      @keys.push(Keyboard::R_Shift) if Keyboard.testkey(Keyboard::R_Shift)
      @keys.push(Keyboard::L_Ctrl) if Keyboard.testkey(Keyboard::L_Ctrl)
      @keys.push(Keyboard::R_Ctrl) if Keyboard.testkey(Keyboard::R_Ctrl)
      @keys.push(Keyboard::L_Alt) if Keyboard.testkey(Keyboard::L_Alt)
      @keys.push(Keyboard::R_Alt) if Keyboard.testkey(Keyboard::R_Alt)
      @keys.push(Keyboard::Collon) if Keyboard.testkey(Keyboard::Collon)
      @keys.push(Keyboard::Equal) if Keyboard.testkey(Keyboard::Equal)
      @keys.push(Keyboard::Comma) if Keyboard.testkey(Keyboard::Comma)
      @keys.push(Keyboard::Underscore) if Keyboard.testkey(Keyboard::Underscore)
      @keys.push(Keyboard::Dot) if Keyboard.testkey(Keyboard::Dot)
      @keys.push(Keyboard::Frontslash) if Keyboard.testkey(Keyboard::Frontslash)
      @keys.push(Keyboard::Tilde) if Keyboard.testkey(Keyboard::Tilde)
      @keys.push(Keyboard::Lb) if Keyboard.testkey(Keyboard::Lb)
      @keys.push(Keyboard::Backslash) if Keyboard.testkey(Keyboard::Backslash)
      @keys.push(Keyboard::Rb) if Keyboard.testkey(Keyboard::Rb)
      @keys.push(Keyboard::Quote) if Keyboard.testkey(Keyboard::Quote)
      @pressed = []
      @pressed.push(Keyboard::Mouse_Left) if Keyboard.getstate(Keyboard::Mouse_Left)
      @pressed.push(Keyboard::Mouse_Right) if Keyboard.getstate(Keyboard::Mouse_Right)
      @pressed.push(Keyboard::Mouse_Middle) if Keyboard.getstate(Keyboard::Mouse_Middle)
      @pressed.push(Keyboard::Back) if Keyboard.getstate(Keyboard::Back)
      @pressed.push(Keyboard::Tab) if Keyboard.getstate(Keyboard::Tab)
      @pressed.push(Keyboard::Enter) if Keyboard.getstate(Keyboard::Enter)
      @pressed.push(Keyboard::Shift) if Keyboard.getstate(Keyboard::Shift)
      @pressed.push(Keyboard::Ctrl) if Keyboard.getstate(Keyboard::Ctrl)
      @pressed.push(Keyboard::Alt) if Keyboard.getstate(Keyboard::Alt)
      @pressed.push(Keyboard::Pause) if Keyboard.getstate(Keyboard::Pause)
      @pressed.push(Keyboard::Caps_Lock) if Keyboard.getstate(Keyboard::Caps_Lock)
      @pressed.push(Keyboard::Esc) if Keyboard.getstate(Keyboard::Esc)
      @pressed.push(Keyboard::Space) if Keyboard.getstate(Keyboard::Space)
      @pressed.push(Keyboard::PgUp) if Keyboard.getstate(Keyboard::PgUp)
      @pressed.push(Keyboard::PgDn) if Keyboard.getstate(Keyboard::PgDn)
      @pressed.push(Keyboard::End) if Keyboard.getstate(Keyboard::End)
      @pressed.push(Keyboard::Home) if Keyboard.getstate(Keyboard::Home)
      @pressed.push(Keyboard::Left) if Keyboard.getstate(Keyboard::Left)
      @pressed.push(Keyboard::Up) if Keyboard.getstate(Keyboard::Up)
      @pressed.push(Keyboard::Right) if Keyboard.getstate(Keyboard::Right)
      @pressed.push(Keyboard::Down) if Keyboard.getstate(Keyboard::Down)
      @pressed.push(Keyboard::Print_Screen) if Keyboard.getstate(Keyboard::Print_Screen)
      @pressed.push(Keyboard::Insert) if Keyboard.getstate(Keyboard::Insert)
      @pressed.push(Keyboard::Delete) if Keyboard.getstate(Keyboard::Delete)
      for key in Keyboard::Numberkeys.values
        @pressed.push(key) if Keyboard.getstate(key)
      end
      for key in Keyboard::Numberpad.values
        @pressed.push(key) if Keyboard.getstate(key)
      end
      for key in Keyboard::Letters.values
        @pressed.push(key) if Keyboard.getstate(key)
      end
      @pressed.push(Keyboard::L_Windows) if Keyboard.getstate(Keyboard::L_Windows)
      @pressed.push(Keyboard::R_Windows) if Keyboard.getstate(Keyboard::R_Windows)
      @pressed.push(Keyboard::Application) if Keyboard.getstate(Keyboard::Application)
      for key in Keyboard::Fkeys.values
        @pressed.push(key) if Keyboard.getstate(key)
      end
      @pressed.push(Keyboard::NumLock) if Keyboard.getstate(Keyboard::NumLock)
      @pressed.push(Keyboard::Scroll_Lock) if Keyboard.getstate(Keyboard::Scroll_Lock)
      @pressed.push(Keyboard::L_Shift) if Keyboard.getstate(Keyboard::L_Shift)
      @pressed.push(Keyboard::R_Shift) if Keyboard.getstate(Keyboard::R_Shift)
      @pressed.push(Keyboard::L_Ctrl) if Keyboard.getstate(Keyboard::L_Ctrl)
      @pressed.push(Keyboard::R_Ctrl) if Keyboard.getstate(Keyboard::R_Ctrl)
      @pressed.push(Keyboard::L_Alt) if Keyboard.getstate(Keyboard::L_Alt)
      @pressed.push(Keyboard::R_Alt) if Keyboard.getstate(Keyboard::R_Alt)
      @pressed.push(Keyboard::Collon) if Keyboard.getstate(Keyboard::Collon)
      @pressed.push(Keyboard::Equal) if Keyboard.getstate(Keyboard::Equal)
      @pressed.push(Keyboard::Comma) if Keyboard.getstate(Keyboard::Comma)
      @pressed.push(Keyboard::Underscore) if Keyboard.getstate(Keyboard::Underscore)
      @pressed.push(Keyboard::Dot) if Keyboard.getstate(Keyboard::Dot)
      @pressed.push(Keyboard::Frontslash) if Keyboard.getstate(Keyboard::Frontslash)
      @pressed.push(Keyboard::Tilde) if Keyboard.getstate(Keyboard::Tilde)
      @pressed.push(Keyboard::Lb) if Keyboard.getstate(Keyboard::Lb)
      @pressed.push(Keyboard::Backslash) if Keyboard.getstate(Keyboard::Backslash)
      @pressed.push(Keyboard::Rb) if Keyboard.getstate(Keyboard::Rb)
      @pressed.push(Keyboard::Quote) if Keyboard.getstate(Keyboard::Quote)
    end
    #--------------------------------------------------------------------------
    def Keyboard.trigger?(key)
      return true if @keys.include?(key)
      return false
    end
    #--------------------------------------------------------------------------
    def Keyboard.pressed?(key)
      return true if @pressed.include?(key)
      return false
    end
  end

#------------------------------------------------------------------------------
# * End SDK Enable Test
#------------------------------------------------------------------------------
end
Code:
#==============================================================================
# ** Mouse Input Module
#------------------------------------------------------------------------------
# Near Fantastica
# Version 5
# 01.03.06
#------------------------------------------------------------------------------
# This module defines mouse input
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log("Mouse Input", "Near Fantastica", 5, "01.03.06")

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.state("Mouse Input") == true

module Mouse
  @position
  GSM = Win32API.new('user32', 'GetSystemMetrics', 'i', 'i')
  Cursor_Pos= Win32API.new('user32', 'GetCursorPos', 'p', 'i')
  Scr2cli = Win32API.new('user32', 'ScreenToClient', %w(l p), 'i')
  Client_rect = Win32API.new('user32', 'GetClientRect', %w(l p), 'i')
  Readini = Win32API.new('kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l')
  Findwindow = Win32API.new('user32', 'FindWindowA', %w(p p), 'l')
  #--------------------------------------------------------------------------  
  def Mouse.grid
    return nil if @pos == nil
    offsetx = $game_map.display_x / 4
    offsety = $game_map.display_y / 4
    x = (@pos[0] + offsetx) / 32
    y = (@pos[1] + offsety) / 32
    return [x, y]
  end
  #--------------------------------------------------------------------------  
  def Mouse.position
    return @pos == nil ? [0, 0] : @pos
  end
  #--------------------------------------------------------------------------  
  def Mouse.global_pos
    pos = [0, 0].pack('ll')
    if Cursor_Pos.call(pos) != 0
      return pos.unpack('ll')
    else
      return nil
    end
  end
  #--------------------------------------------------------------------------  
  def Mouse.pos
    x, y = Mouse.screen_to_client(*Mouse.global_pos)
    width, height = Mouse.client_size
    begin
      if (x >= 0 and y >= 0 and x < width and y < height)
        return x, y
      else
        return nil
      end
    rescue
      return nil
    end
  end
  #--------------------------------------------------------------------------  
  def Mouse.update
    @pos = Mouse.pos
  end
  #--------------------------------------------------------------------------  
  def Mouse.screen_to_client(x, y)
    return nil unless x and y
    pos = [x, y].pack('ll')
    if Scr2cli.call(Mouse.hwnd, pos) != 0
      return pos.unpack('ll')
    else
      return nil
    end
  end
  #--------------------------------------------------------------------------  
  def Mouse.hwnd
    game_name = "\0" * 256
    Readini.call('Game','Title','',game_name,255,".\\Game.ini")
    game_name.delete!("\0")
    return Findwindow.call('RGSS Player',game_name)
  end
  #--------------------------------------------------------------------------  
  def Mouse.client_size
    rect = [0, 0, 0, 0].pack('l4')
    Client_rect.call(Mouse.hwnd, rect)
    right, bottom = rect.unpack('l4')[2..3]
    return right, bottom
  end
end

#------------------------------------------------------------------------------
# * End SDK Enable Test
#------------------------------------------------------------------------------
end
and my characterset to illustrate easier the 8 directions:
http://www.geocities.com/draycosgoldaryn/rock-point.PNG[/img]
 
DraycosGoldaryn;175217 said:
I have Near_Fantastica's Pathfinding script. The only problem is that it only moves the character in four directions. I also have my own script which allows for facing in 8 directions and have tried editing Near's script to allow 8 directional movement. My only problem is when the script is called, the character moves as it should, except it faces seemingly random directions as it moves, not always the direction in which it is moving.
it seems that maybe you need to call the direction movement when you store the variable array for the coordinates. Also check your spritesheet. Sometimes certain scripts call different cell frames. so if your DownRight pose is in the down cell, the it looks like they face random ways. I found that out with DerVVulfman's 8 direction script. All it took was to move a row or two and it works great. try that and maybe that'll solve the problem.

Other than that I'm not so hot with Ruby so there's a limitation with me. I'm sure a mod or someone with scripting knowledge will glance at this thread and hopefully help you.
 
SamusK;178309":2q7759rd said:
it seems that maybe you need to call the direction movement when you store the variable array for the coordinates.

Code:
      dir = rand(4)
      case dir
      when 0
        move_upper_right if @map[@x+1,@y-1] == step - 1 and step != 0
        move_lower_right if @map[@x+1,@y+1] == step - 1 and step != 0
        move_lower_left if @map[@x-1,@y+1] == step - 1 and step != 0
        move_upper_left if @map[@x-1,@y-1] == step - 1 and step != 0
      when 1
        move_down if @map[@x,@y+1] == step - 1 and step != 0
        move_right if @map[@x+1,@y] == step - 1 and step != 0
        move_left if @map[@x-1,@y] == step -1 and step != 0
        move_up if @map[@x,@y-1] == step - 1 and step != 0
      when 2
        move_upper_left if @map[@x-1,@y-1] == step - 1 and step != 0
        move_lower_left if @map[@x-1,@y+1] == step - 1 and step != 0
        move_lower_right if @map[@x+1,@y+1] == step - 1 and step != 0
        move_upper_right if @map[@x+1,@y-1] == step - 1 and step != 0
      when 3
        move_up if @map[@x,@y-1] == step - 1 and step != 0
        move_left if @map[@x-1,@y] == step -1 and step != 0
        move_down if @map[@x,@y+1] == step - 1 and step != 0
        move_right if @map[@x+1,@y] == step - 1 and step != 0
      end
And the four non default directions are defined here:
Code:
class Game_Character
  #--------------------------------------------------------------------------
  # * Move Lower Left
  #--------------------------------------------------------------------------
  def move_lower_left(turn_enabled = true)
    # Turn up
    if turn_enabled
      turn_lower_left
    end
    # When a down to left or a left to down course is passable
    if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
       (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
      # Update coordinates
      @x -= 1
      @y += 1
      # Increase steps
      increase_steps
    # If impassable
    else
      # Determine if touch event is triggered
      check_event_trigger_touch(@x-1, @y+1)
    end
  end
  #--------------------------------------------------------------------------
  # * Move Lower Right
  #--------------------------------------------------------------------------
  def move_lower_right(turn_enabled = true)
    # Turn up
    if turn_enabled
      turn_lower_right
    end
    # When a down to right or a right to down course is passable
    if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
       (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
      # Update coordinates
      @x += 1
      @y += 1
      # Increase steps
      increase_steps
    # If impassable
    else
      # Determine if touch event is triggered
      check_event_trigger_touch(@x+1, @y+1)
    end
  end
  #--------------------------------------------------------------------------
  # * Move Upper Left
  #--------------------------------------------------------------------------
  def move_upper_left(turn_enabled = true)
    # Turn up
    if turn_enabled
      turn_upper_left
    end
    # When an up to left or a left to up course is passable
    if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
       (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
      # Update coordinates
      @x -= 1
      @y -= 1
      # Increase steps
      increase_steps
    # If impassable
    else
      # Determine if touch event is triggered
      check_event_trigger_touch(@x-1, @y-1)
    end
  end
  #--------------------------------------------------------------------------
  # * Move Upper Right
  #--------------------------------------------------------------------------
  def move_upper_right(turn_enabled = true)
    # Turn up
    if turn_enabled
      turn_upper_right
    end
    # When an up to right or a right to up course is passable
    if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
       (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
      # Update coordinates
      @x += 1
      @y -= 1
      # Increase steps
      increase_steps
    # If impassable
    else
      # Determine if touch event is triggered
      check_event_trigger_touch(@x+1, @y-1)
    end
  end
SamusK;178309":2q7759rd said:
Also check your spritesheet. Sometimes certain scripts call different cell frames. so if your DownRight pose is in the down cell, the it looks like they face random ways. I found that out with DerVVulfman's 8 direction script. All it took was to move a row or two and it works great. try that and maybe that'll solve the problem.

The cell frame arrangement is defined here:
Code:
 self.bitmap = RPG::Cache.character(@character.character_name,
          @character.character_hue)
        @cw = bitmap.width / 4
        @ch = bitmap.height / 8
        self.ox = @cw / 2
        self.oy = @ch
      end
    end
    # Set visible situation
    self.visible = (not @character.transparent)
    # If graphic is character
    if @tile_id == 0
      # Set rectangular transfer
      sx = @character.pattern * @cw
      if @character.direction >= 6
        sy = (@character.direction - 2 ) * @ch
      else
        sy = (@character.direction - 1 ) * @ch
      end
      self.src_rect.set(sx, sy, @cw, @ch)
    end
@ch = bitmap.height / 8 shows 8 directions.
Code:
 if @character.direction >= 6
        sy = (@character.direction - 2 ) * @ch
      else
        sy = (@character.direction - 1 ) * @ch
      end
sets which row is which direction. So that isn't the problem, because they face the right way when using the other movement methods as defined in my 8-direction script. Only when pathfinding. Sometimes the character will face up whne moving upper left or upper right; down when moving lower left or lower right, or diagonal when moving horizontally or vertically.

SamusK;178309":2q7759rd said:
Other than that I'm not so hot with Ruby so there's a limitation with me. I'm sure a mod or someone with scripting knowledge will glance at this thread and hopefully help you.
Thanks for trying to help though.
 
Hey! Don't get disheartened. For one, I too want an 8-dir pathfinding because I almost always use 8-dir movement in my games. Why not try requesting the script somewhere in the forum? I think I've came across some "8-dir addon" scripts in the script listings. Check them out and you might get lucky. If you do, though, would you please leave a link? I can sure use pathfinding.
 
I'm currently working on a pathfinding script but sadly its also 4 directional movement, maybe i will upgrade it in a future version.

Your problem is because using A* pathfinding for 8directional movement is more costly as there are more tiles to examine Near probably restricted it for that reason... either that or he didn't want to make it 8 directional.

In order to get 8 directional movement you will need to edit the part of the script that searches the four adjacent tiles to the currently active square as well as the movement section... to do this you will need to gain an understanding of how A* pathfinding works this link is an excellent one: http://www.policyalmanac.org/games/aStarTutorial.htm

Oh and also you need to add a special rule to take into account diagonal walls,
I.e.
http://img520.imageshack.us/img520/3930/untitledvu4.jpg[/img]
Obviously you don't want to walk along that arrow but you need to add a rule or the algorithm can't tell it from the rest.


I have an old pathfinding script that i posted back on RMXP.net that uses a different algorithm to A* but it will be no easier to modify.


In short: Even though you have added the extra directions for movement, the script is till predicting a 4 directional path. You need to edit the 'meat' of the pathfinding script.

Edit: Didn't realise you had posted the script, that doesn't look like A* pathfinding to me, i was assuming that it was the script that Near had posted around when i posted my last one, so i don't know if what is said is any help to you. If i manage to get my pathfinding working i will upgrade it to 8 directional at somestage.
 
Thank you eivien for your help. My biggest problem with editing this script is that Near did not include any comments to explain what certain code blocks do, so It is hard for me to understand what to change. But, after taking a look at the link you provided, I might try to write my own pathfinding script using A*, if no one beats me to it.

Thank you.
 
Well if you hold your horses, ive finished my pathfinding script and finally got it working i'm just working on the front end which will make an event follow the path before i release it.
The hardest part about making an efficient implementation is the fact you need to implement two lists and without the use of pointers these really need to be implemented within arrays.
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top