Falling off spiral stairs

Posted By: Ruben

Falling off spiral stairs - 06/23/16 04:08

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.
Posted By: Anonymous

Re: Falling off spiral stairs - 06/23/16 04:27

Lol you found a bug in my basic path system.

If you will give me till tomorrow afternoon I'll write a post and solution. Right now is late and I'm celebrating my work week Friday.

Basiclly run a for loop
set node to 1
jump through each node - for loop i++
check all node to object distance
store in var closest this winner of check
winner == node out of all node that is smallest vec_dist(my.x my.node_next)
You've found the closest.
Posted By: Anonymous

Re: Falling off spiral stairs - 06/23/16 17:56


Code:
// find closest node
// using  -> // node 247 = top of stairs 
int i=0;
var node_closest_dist= 99999; /// Very high start number
int close_node_winner=0; //
VECTOR vec_temp_node;

// checking all node distances 
for(i=0;i<247;i++)
{
   path_getnode(my,i+1,vec_temp_node,NULL);
   if(vec_dist(my.x,vec_temp_node)< node_closest_dist)
   {
     node_closest_dist=vec_dist(my.x,vec_temp_node);
     close_node_winner = i+1;
   }
}
// After checking - assign winner and reset values
my.NODE_NEXT = close_node_winner;
close_node_winner =0;
node_closest_dist = 999999;

Posted By: Ruben

Re: Falling off spiral stairs - 06/24/16 07:40

Thank you Malice. I will try it out, and let you know how it goes.
Posted By: Ruben

Re: Falling off spiral stairs - 07/10/16 17:19

Thank you Malice! Your code worked great. Sorry it took me so long to respond to you. I had a lot of other things going on in life that kept me from programming as much as I would have liked.

Plus, I was trying to figure out a way to make it so that the program detected when the enemy fell off the stairs, in order to find the closest node in the first place. I finally made the first part work, along with your code, and it seems to work great. I have a little tweaking I need to do to make the process run smoothly and perfectly, but it is about 80-90% there. Again, thank you. :-)
Posted By: Anonymous

Re: Falling off spiral stairs - 07/10/16 18:13

Your welcome...

Happy it worked

Take Care --
© 2024 lite-C Forums