I have a spiral staircase along the wall, inside a hollow cigar shape vertical tower, in my game. I set a path using the path_set() function (with nodes) along the spiral staircase, so that an enemy can chase the player up or down the spiral staircase along the path. This is working just fine.

Now, lets say the player somehow backs the enemy off the spiral staircase, so that the enemy falls off the spiral staircase, dropping below. The enemy might drop on the next lower rung of the spiral staircase, or wherever. I am trying to find a function or method that will look for the "closest path node" that the enemy drops down to, and that node will be set to the next node for the enemy to run to along the path, in order to chase the player up the stairs from the location that the enemy fell to.

This is the code I have so far:

Code:
action path_setEnemy()
{
   proc_kill2(path_setEnemy,my);
   VECTOR vec_next_node;

   VECTOR temp;
	
   path_set(my,"path_001");

   while(1)
   {
      // PATH NODE DETECTION AND FACING ///////////////

      if(vec_dist(my.x,vec_next_node.x) < 80) 
      {    
         if(pathSetNum_enemy == 1) // enemy runs down stairs
	 {
	    my.NODE_NEXT+=1; 
	 }
		 
	 if(pathSetNum_enemy == 2) // enemy runs up stairs
         {
            my.NODE_NEXT-=1; 
	 }
	         
	 if(my.NODE_NEXT > 247) // node 247 = top of stairs 
                                //    node
	 {
	    my.NODE_NEXT = 247;	
         }
		    	
         if(my.NODE_NEXT < 1) // node 1 = bottom of stairs node
	 {
	    my.NODE_NEXT = 1;	
         }
      }
		
      path_getnode(my,my.NODE_NEXT,vec_next_node,NULL); 
         // gets the next node 
     
      vec_to_angle(my.pan,vec_diff(NULL,vec_next_node.x,my.x));
         // face the new node
		
      wait(1);
   }
}



As of right now, if the enemy falls off the spiral staircase, and lands (lets say) on the next spiral staircase rung below, the enemy ends up running up through the air toward what would have been the next node, had the enemy never fallen off the staircase.

Is there a way to alter this code:

Code:
path_getnode(my,my.NODE_NEXT,vec_next_node,NULL);



...so that the next node can be set to the closest node in distance to the enemy, instead of the next node that was set before the enemy fall off the stairs?

Any help would be appreciated. Thank you.