//resets veriables
wall_check_right=0
wall_check_left=0
wall_check_up=0
wall_check_down=0
dound_mid=0
right_dist=0
left_dist=0
up_dist=0
down_dist=0
//rules out prior direction
if direction=180 then wall_check_right=1
if direction=0then wall_check_left=1
if direction=270then wall_check_up=1
if direction=90 then wall_check_down=1
//find where walls are
if position_meeting(x+32,y+16,wall) then wall_check_right=1
if position_meeting(x-32,y+16,wall) then wall_check_left=1
if position_meeting(x+16,y-32,wall) then wall_check_up=1
if position_meeting(x+16,y+32,wall) then wall_check_down=1
// now all possable paths are found- take remainder paths and find which is closest to target vector (for now player)
//finds values of directions + if not a valid direction, makes sure not an optional min
if wall_check_right =0 then
{right_dist=point_distance(self.x+32,self.y,player.x,player.y)}else {right_dist=10003}
if wall_check_left =0 then
{left_dist=point_distance(self.x-32,self.y,player.x,player.y)}else {left_dist=10002}
if wall_check_up =0 then
{up_dist=point_distance(self.x,self.y-32,player.x,player.y)}else {up_dist=10001}
if wall_check_down =0then
{down_dist=point_distance(self.x,self.y+32,player.x,player.y)}else {down_dist=10000}
//finds lowest distance
found_min=min(right_dist,left_dist,up_dist,down_dist)
//finds which value was min and returns to variable rather then integer then decides direction
if right_dist=found_min then direction=0
if left_dist=found_min then direction=180
if up_dist=found_min then direction=90
if down_dist=found_min then direction=270
//notes* getting the npc into a cornered position will take on errors or be forced into order of operation conflicts- no longer a conflict
any help would be greatIt also takes place in step under a D&D check aligned by 32x32 with all variables in initiated in create event
Edited by roa, 18 May 2012 - 03:02 AM.











