Kevvviiinnn
Member
How does one get an event (or the player) to jump towards a specified event (or uhh...player)?
$game_map.events[event_id].jump(x_plus, y_plus)
# or for the player
$game_player.jump(x_plus, y_plus)
#==============================================================================
# ** Game_Character (Jump Commands By SephirothSpawn)
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# * Jump toward character
#--------------------------------------------------------------------------
def jump_toward_character(character = $game_player)
# Get difference in player coordinates
sx = @x - character.x
sy = @y - character.y
# If coordinates are equal
if sx == 0 and sy == 0
return
end
# Get absolute value of difference
abs_sx = sx.abs
abs_sy = sy.abs
# If horizontal and vertical distances are equal
if abs_sx == abs_sy
# Increase one of them randomly by 1
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
# If horizontal distance is longer
if abs_sx > abs_sy
# Jump towards character, prioritize left and right directions
sx > 0 ? jump(-1, 0) : jump(1, 0)
if not jumping? and sy != 0
sy > 0 ? jump(0, -1) : jump(0, 1)
end
# If vertical distance is longer
else
# Jump towards character, prioritize up and down directions
sy > 0 ? jump(0, -1) : jump(0, 1)
if not jumping? and sx != 0
sx > 0 ? jump(-1, 0) : jump(1, 0)
end
end
end
#--------------------------------------------------------------------------
# * Jump away from character
#--------------------------------------------------------------------------
def jump_away_from_character(character = $game_player)
# Get difference in player coordinates
sx = @x - character.x
sy = @y - character.y
# If coordinates are equal
if sx == 0 and sy == 0
return
end
# Get absolute value of difference
abs_sx = sx.abs
abs_sy = sy.abs
# If horizontal and vertical distances are equal
if abs_sx == abs_sy
# Increase one of them randomly by 1
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
# If horizontal distance is longer
if abs_sx > abs_sy
# Jump away from character, prioritize left and right directions
sx > 0 ? jump(1, 0) : jump(-1, 0)
if not jumping? and sy != 0
sy > 0 ? jump(0, 1) : jump(0, -1)
end
# If vertical distance is longer
else
# Jump away from character, prioritize up and down directions
sy > 0 ? jump(0, 1) : jump(0, -1)
if not jumping? and sx != 0
sx > 0 ? jump(1, 0) : jump(-1, 0)
end
end
end
end
e1 = <character>
e2 = <character>
-then-
e1.jump_toward_character(e2)
-or-
e1.jump_away_from_character(e2)