Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (howardR, sleakz), 688 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Falling off spiral stairs #460278
06/23/16 04:08
06/23/16 04:08
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
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.

Re: Falling off spiral stairs [Re: Ruben] #460279
06/23/16 04:27
06/23/16 04:27

M
Malice
Unregistered
Malice
Unregistered
M



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.

Re: Falling off spiral stairs [Re: ] #460288
06/23/16 17:56
06/23/16 17:56

M
Malice
Unregistered
Malice
Unregistered
M




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;


Re: Falling off spiral stairs [Re: ] #460302
06/24/16 07:40
06/24/16 07:40
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Thank you Malice. I will try it out, and let you know how it goes.

Re: Falling off spiral stairs [Re: Ruben] #460680
07/10/16 17:19
07/10/16 17:19
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
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. :-)

Re: Falling off spiral stairs [Re: Ruben] #460686
07/10/16 18:13
07/10/16 18:13

M
Malice
Unregistered
Malice
Unregistered
M



Your welcome...

Happy it worked

Take Care --


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1