Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
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
1 registered members (rki), 405 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
2 paths interferring? #456112
11/10/15 05:12
11/10/15 05:12
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 inside a circular tower. When I move the player close enough to an enemy standing guard on a section of the spiral staircase (with the player being lower on the z axis than the enemy) using c_scan(), the enemy runs downs a path called "path_001" that runs down a certain way down the spiral staircase. If the player runs past the enemy and ends up being above the enemy on the spiral staircase (where the player is higher on the z axis than the enemy), I have a second path called "path_002" that the enemy is supposed to run up in order to catch up to the player, or at least to the end of the path.

The enemy runs down "path_001" just fine along all its four nodes when the player gets close enough to it. However, when the player runs above the enemy on the spiral staircase, and the enemy chases the player by moving up along "path_002", the enemy will get as far as the second node (out of four), and not get past the second node.

Here is my code for this:

Code:
...

action path_setter_1()
{
   ...

   path_set(my,"path_001"); // Move down spiral staircase

   ...
}

action path_setter_2()
{
   ...

   path_set(my,"path_002"); // Move up spiral staircase

   ...
}

action monster_code()
{
   ...

   while(1)
   {
      c_scan(my.x,my.pan,vector(360,0,750),SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME);

      if(you)
      {
         ...

         path_setter_1(); // If player gets close enough, 
            //   monster runs down spiral staircase to get to
            //   player.

         ...

         if((hero.z > 50) && (hero.z > my.z))
         {
            path_setter_2(); // If player runs past monster,
               //    and gets above monster on spiral 
               //    staircase, monster chases player up
               //    spiral staircase.
         }

         c_move(my, vector(8 * time_step, 0, 0), nullvector, GLIDE);
         
         ent_animate(my, "run", anim_percentage, ANM_CYCLE);
         anim_percentage += 8 * time_step;

         ...
      }

      ...

      wait(1);
   }
}



If I debug to where the enemy starts out at the beginning of "path_002", and the player gets close enough to the enemy causing the enemy to only move up "path_002" (leaving the "path_001" call out), the enemy moves up along "path_002" just fine along all four nodes.

Basically "path_001" and "path_002" run along the same area, except "path_001" goes down the spiral staircase, and "path_002" goes up the spiral staircase.

Are "path_001" and "path_002" somehow interfering with each other? Has anyone else had this problem?

Is there a way to only use one path, and have the enemy simply reverse direction as needed on the same path?

Last edited by Ruben; 11/10/15 18:30.
Re: 2 paths interferring? [Re: Ruben] #456170
11/13/15 02:06
11/13/15 02:06
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
So, it appears that whatever path is set first allows the monster to move along that path perfectly. Whatever path is set second, the monster is only able to move to the second node (after the initial node), but cannot move past the second node.

For example:

(1) The player enters a tower with a spiral staircase. A monster is standing on a certain location along the spiral staircase, which is not very far off the bottom of the tower, maybe 30 feet by our real standard.

(2) The player moves a certain distance toward the monster. If the monster's c_scan() detects the player, the monster will proceed to run down the "path_001" path, which goes down the spiral staircase to the bottom of the tower.

(3) Once the monster gets to the bottom of the tower, the monster will face and run toward the player.

(4) If the player runs past the monster and tries to escape it by moving up the spiral staircase, this should trigger the monster to start moving up "path_002" (chasing the player up the spiral staircase), whose nodes are on the same points as "path_001", except that "path_002"'s direction is moving up the spiral staircase, not down it as "path_001" does.

(5) Once the monster gets to the second node in "path_002", the monster stops moving.

I have tried reversing "path_001" and "path_002"'s order, to where if the player moves toward the monster in the beginning and the monster's c_scan() is triggered by the player, the monster will run in the air from the location it was on on the spiral staircase (30 feet over the bottom of the tower), toward the start of "path_002" at the bottom of spiral staircase, and then start moving up the staircase. When this happens, the monster moves up "path_002" just fine along all nodes.

If the player chases the monster up the spiral staircase as it moves along "path_002", and runs past it to where the player is higher on the z axis than the monster, the monster will start moving along "path_001" down the spiral staircase, but also will not get past the second node.

Here is my code in trying to make all this happen:

Code:
action monster_action() 
{
   ...
	
   while (1)
   { 
      ...
		
      c_scan(my.x,my.pan,vector(360,0,750),SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME);
			
      if (you) // player detected?
      {  
         pathSetNum = 1;
	
         path_setter();
					
         ...
			
         my.STATE = 2; 	
      }				
   }
	
   if (my.STATE == 2) 
   {				
      if((hero.z > 50) && (hero.z > my.z)) // player is above
         //    bottom of tower, and monster
      {
         pathSetNum = 2;
	 path_setter();
      }
			
      if((my.z >= 47) && (my.z <= 49)) // once on bottom of 
         //    tower, monster faces and runs toward player
      {
         path_set(my,NULL);
				 
         vec_set(temp.x, player.x);
         vec_sub(temp.x, my.x);
         vec_to_angle(my.pan, temp); // rotate the enemy towards the player
      }

      c_move(my, vector(8 * time_step, 0, 0), nullvector, GLIDE);

      ent_animate(my, "run", anim_percentage, ANM_CYCLE);
      anim_percentage += 8 * time_step;
			
      ...
   }
      
   wait(1);
}


...

action path_setter()
{
   VECTOR vec_next_node;

   path_set(my,NULL);
	
   if(pathSetNum == 1) // whatever path is set here works perfectly
   {
      //path_set(my,"path_002");
      path_set(demon,"path_001");
   }
	
   if(pathSetNum == 2) // whatever path is set here does not allow monster to
                       //    move past second node
   {
      //path_set(my,"path_001");
      path_set(demon,"path_002");
   }
	
   my.NODE_NEXT=path_nextnode(my,1,1); // SET THE NODE
	
   while(1)
   {
      // PATH NODE DETECTION AND FACING //////////////////////////////////
		
      if(vec_dist(my.x,vec_next_node.x) < 80) 
      {    
         my.NODE_NEXT=path_nextnode(my,my.NODE_NEXT,1); // Grab Next node on 
                                                        //    path	
      }
		
      path_getnode(my,my.NODE_NEXT,vec_next_node,NULL);  // Get next node actual vector location 
		
      vec_to_angle(my.pan,vec_diff(NULL,vec_next_node,my.x)); // face the new node
		
      wait(1);
   }
}



So, somehow the path that the monster travels after the first path does not allow the monster to move past the second node, but the first path works just fine for the monster, whatever order "path_001" or "path_002" are in.

Anyone have a clue why? Any help would be appreciated. Thank you.

Last edited by Ruben; 11/13/15 02:22.
Re: 2 paths interferring? [Re: Ruben] #456171
11/13/15 03:18
11/13/15 03:18

M
Malice
Unregistered
Malice
Unregistered
M



I would guess that the error has to be here
Code:
if((hero.z > 50) && (hero.z > my.z)) // player is above
         //    bottom of tower, and monster
      {
         pathSetNum = 2;
	 path_setter();
      }
			
      if((my.z >= 47) && (my.z <= 49)) // once on bottom of 
         //    tower, monster faces and runs toward player
      {
         path_set(my,NULL);
				 
         vec_set(temp.x, player.x);
         vec_sub(temp.x, my.x);
         vec_to_angle(my.pan, temp); // rotate the enemy towards the player
      }



However if you manually control my.NODE_NEXT, you can use the same path. Can't you set_nodenext(my,-1,1);

However in state 2 , set my.NODE_NEXT to last node, then manually subtract -1 from it. This should cause the monster to travel backward up path_001 without the need of another path.

if at node 1 use as written, to reverse

stop getting path_nextnode, instead manual sub from my.NODE_NEXT-=1; then plug the new ,backward node into path_getnode(my,my.NODE_NEXT,vec_next_node,NULL);

Here is the new code
Code:
action path_setter()
{
	VECTOR vec_next_node;
	path_set(my,NULL);
	path_set(demon,"path_001");
	
	my.NODE_NEXT=path_nextnode(my,1,1); // SET THE NODE
	
	while(1)
	{
		// PATH NODE DETECTION AND FACING //////////////////////////////////
		
		if(vec_dist(my.x,vec_next_node.x) < 80) 
		{    
			if(pathSetNum == 1) // whatever path is set here does not allow monster to
			{

				my.NODE_NEXT=path_nextnode(my,my.NODE_NEXT,1); // Grab Next node on 
			//    path	
			}
			if(pathSetNum == 2) // whatever path is set here does not allow monster to
			//    move past second node
			{
				my.NODE_NEXT-=1;
				if(my.NODE_NEXT<1)
				my.NODE_NEXT=1;
				// limit node not to fall below 0 or maybe that will auto revrse
			}
		}
		
		path_getnode(my,my.NODE_NEXT,vec_next_node,NULL);  // Get next node actual vector location 
		
		vec_to_angle(my.pan,vec_diff(NULL,vec_next_node,my.x)); // face the new node
		
DEBUG_VAR(my.NODE_NEXT,500);
		wait(1);
	}
}



Give that a look and a run, I can't test it.
Mal


LOL are you detaching when you reach node 2 by calling path_set(my,NULL);
to many times?
IF my.NODE_NEXT is dropping to 0 then you be.

Ok bye now
Mal


Last edited by Malice; 11/13/15 03:40.
Re: 2 paths interferring? [Re: ] #456207
11/14/15 21:06
11/14/15 21:06
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Thank you Malice. And just to let you know, I am not ignoring you. I am currently trying to make it work. The code is working in making the monster go back up "path_001", however, instead of going up the path in order from nodes 4 to 1, the monster seems to go straight to node 2 while skipping 4 and 3. Or it might be going from node 4 straight to 2 while skipping 3. I am trying to figure out how to make it work.

Re: 2 paths interferring? [Re: Ruben] #456208
11/14/15 21:38
11/14/15 21:38

M
Malice
Unregistered
Malice
Unregistered
M



Code:
if(vec_dist(my.x,vec_next_node.x) < 80) 
		{    
			if(pathSetNum == 1) // whatever path is set here does not allow monster to
			{



If this 80 is to large, you can end up reading 4 and 3 in a frame or two. Try,
if(vec_dist(my.x,vec_next_node.x) < my.max_x*1.5)
or
if(vec_dist(my.x,vec_next_node.x) <my.max_x-my.min_z)

if this ->DEBUG_VAR(my.NODE_NEXT,500);

jumps from 4 to 1 , you know it works however it sees 2-3 faster then the human eye. Again pointing use to the vec_dist check

Edit _> before it changes direction make sure you see 4 in-> DEBUG_VAR(my.NODE_NEXT,500); and then confirm the next number is 2, also confirm it never changes to 1.
Debugging and troubleshooting, it's a art form, after years you begin to just feel it. Of course debugging in a forum post is a pain, however a few years of it can make you excellent at hunting down problems.
Mal

Mal


Last edited by Malice; 11/14/15 21:46.
Re: 2 paths interferring? [Re: ] #456209
11/14/15 22:48
11/14/15 22:48

M
Malice
Unregistered
Malice
Unregistered
M



Other possibilities this function is being called to often-> path_setter();

a simple debug would be to make a global var , then in function path_setter();
v_global+=1; and in it's loop DEBUG_VAR(v_global,100);

In fact if I look close at the code you posted you call this function ->path_setter();
twice, however the function is a self contained loop, and so you have 2 instances of the same function running the same loop. That would cause my>NODE_NEXT to be set to odd values. Even explain the lock at node num 2.

one loop ready and up and one down while in the same cycle, causing no movement.

Solution -> remove the loop in function ->path_setter();
then it can be a call-out function called every frame by the other loop.
Ok
Mal

Last edited by Malice; 11/14/15 22:50.
Re: 2 paths interferring? [Re: ] #456215
11/15/15 11:28
11/15/15 11:28
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
I think the error may be in the path_setter() function itself.

This is the path_setter() function I am using right now:

Code:
action path_setter()
{
   VECTOR vec_next_node;

   path_set(my,"path_001");
	
   if(pathSetNum == 1)
   {
      my.NODE_NEXT=path_nextnode(my,1,1); // SET THE NODE
   }

   if(pathSetNum == 2)
   {	
      my.NODE_NEXT=4; // SET THE NODE
   }

   while(1)
   {
      // PATH NODE DETECTION AND FACING //////////////////////////////////
		
      if(vec_dist(my.x,vec_next_node.x) < 80) 
      {    
         if(pathSetNum == 1) 
         {
            my.NODE_NEXT=path_nextnode(my,my.NODE_NEXT,1); // Grab Next node on 
         }
	 if(pathSetNum == 2) 
	 {
	    my.NODE_NEXT-=1; // NODE GOES DOWN TO 3, BUT THEN JUMPS BACK UP TO 
                             //    4.
         }
      }
		
      path_getnode(my,my.NODE_NEXT,vec_next_node,NULL);  
         // Get next node - actual vector location
         // I BELIEVE THE ERROR IS HAPPENING HERE, PROBABLY WITH vec_next_node
	
      vec_to_angle(my.pan,vec_diff(NULL,vec_next_node,my.x)); // face the new 
                                                              //    node

      DEBUG_VAR(my.NODE_NEXT,500);
		
      wait(1);
   }
}



I think the error may lie with "vec_next_node". When NODE_NEXT decrements from 4 to 3, it quickly increments back up to 4 instead of staying at 3, and keeps quickly jittering back and forth between 3 and 4, while the monster is within the general vicinity of node 4 and not traveling anywhere.

I think "vec_next_node" is identifying node 4 as the next node vector location from node 3 even when NODE_NEXT is decrementing; when vec_next_node should really stay at node 3 until the monster actually relocates to node 3, to which NODE_NEXT should decrement again to node 2, and so on.

Last edited by Ruben; 11/15/15 11:33.
Re: 2 paths interferring? [Re: Ruben] #456222
11/15/15 18:20
11/15/15 18:20

M
Malice
Unregistered
Malice
Unregistered
M



Quote:
path_getnode(my,my.NODE_NEXT,vec_next_node,NULL);
// Get next node - actual vector location
// I BELIEVE THE ERROR IS HAPPENING HERE, PROBABLY WITH vec_next_node

Quote:
I think the error may lie with "vec_next_node".

WRONG!!

This is in fact quite wrong... path_getnode is like vec_set but you only have the one vec to fill so the function finds the node you name "3" and puts it's real vec into vec_next_node

Quote:
if(pathSetNum == 1)
{
my.NODE_NEXT=path_nextnode(my,my.NODE_NEXT,1); // Grab Next node on
}
if(pathSetNum == 2)
{
my.NODE_NEXT-=1; // NODE GOES DOWN TO 3, BUT THEN JUMPS BACK UP TO
// 4.
}


This is where the error happens. You are seeing it running twice. first it runs if(pathSetNum == 1) then it runs if(pathSetNum == 2), That is why you see the back and forth.

So how is that happening?
1) the code that sets pathSetNum = X is setting it back and forth to 1 and 2.
2) there are two instances of path_setter() running, one set at pathSetNum = 1 and the other at pathSetNum = 2. These to running loops are fighting each other.

My bet is Number 2 - and this is how we will test -here is your new code, if this fixes, than the error is number 2, if not the error is at number 1

This code is a test - How to use this. Run this function and watch the debug_var(test_var,525); It should always be 0 or 1 never higher.. If it's higher you have many running function. Then use script 2 to fix.
Code:
action path_setter()
{
var TEST_VAR=0;
   VECTOR vec_next_node;

   path_set(my,"path_001");
	
   if(pathSetNum == 1)
   {
      my.NODE_NEXT=path_nextnode(my,1,1); // SET THE NODE
   }

   if(pathSetNum == 2)
   {	
      my.NODE_NEXT=4; // SET THE NODE
   }

   while(1)
   {
TEST_VAR=proc_status2 (path_setter, my)
      // PATH NODE DETECTION AND FACING //////////////////////////////////
		
      if(vec_dist(my.x,vec_next_node.x) < 80) 
      {    
         if(pathSetNum == 1) 
         {
            my.NODE_NEXT=path_nextnode(my,my.NODE_NEXT,1); // Grab Next node on 
         }
	 if(pathSetNum == 2) 
	 {
	    my.NODE_NEXT-=1; // NODE GOES DOWN TO 3, BUT THEN JUMPS BACK UP TO 
                             //    4.
         }
      }
		
      path_getnode(my,my.NODE_NEXT,vec_next_node,NULL);  
         // Get next node - actual vector location
         // I BELIEVE THE ERROR IS HAPPENING HERE, PROBABLY WITH vec_next_node
	
      vec_to_angle(my.pan,vec_diff(NULL,vec_next_node,my.x)); // face the new 
                                                              //    node

      DEBUG_VAR(my.NODE_NEXT,500);
      DEBUG_VAR(TEST_VAR,525);
		
      wait(1);
   }
}



Script 2 fixes the issue, however fixing your bad code is perfered to killing functions.
Code:
action path_setter()
{
proc_kill2(path_setter,my);
   VECTOR vec_next_node;

   path_set(my,"path_001");
	
   if(pathSetNum == 1)
   {
      my.NODE_NEXT=path_nextnode(my,1,1); // SET THE NODE
   }

   if(pathSetNum == 2)
   {	
      my.NODE_NEXT=4; // SET THE NODE
   }

   while(1)
   {

      // PATH NODE DETECTION AND FACING //////////////////////////////////
		
      if(vec_dist(my.x,vec_next_node.x) < 80) 
      {    
         if(pathSetNum == 1) 
         {
            my.NODE_NEXT=path_nextnode(my,my.NODE_NEXT,1); // Grab Next node on 
         }
	 if(pathSetNum == 2) 
	 {
	    my.NODE_NEXT-=1; // NODE GOES DOWN TO 3, BUT THEN JUMPS BACK UP TO 
                             //    4.
         }
      }
		
      path_getnode(my,my.NODE_NEXT,vec_next_node,NULL);  
         // Get next node - actual vector location
         // I BELIEVE THE ERROR IS HAPPENING HERE, PROBABLY WITH vec_next_node
	
      vec_to_angle(my.pan,vec_diff(NULL,vec_next_node,my.x)); // face the new 
                                                              //    node	
      wait(1);
   }
}




Your home work - read up on proc_kill and proc_status.

Mal


Last edited by Malice; 11/15/15 18:21.
Re: 2 paths interferring? [Re: ] #456233
11/15/15 20:12
11/15/15 20:12
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Thank you Malice.

I tried using your first function. The TEST_VAR has never gone above 1, so it does not appear that more than one instance of path_setter() is running at the same time.

Despite this, the monster is still having the same problem. Judging by the:

DEBUG_VAR(my.NODE_NEXT,500);

...NEXT_NODE keeps jittering between what appears to be 3 and 4, when the monster approaches the vicinity of node 4 to move back up path_001 .

Re: 2 paths interferring? [Re: Ruben] #456235
11/15/15 20:24
11/15/15 20:24

M
Malice
Unregistered
Malice
Unregistered
M



Then the problem is here
Code:
while (1)
   { 
      ...
		
      c_scan(my.x,my.pan,vector(360,0,750),SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME);
			
      if (you) // player detected?
      {  
         pathSetNum = 1;
	
         path_setter();
					
         ...
			
         my.STATE = 2; 	
      }				
   }
	
   if (my.STATE == 2) 
   {				
      if((hero.z > 50) && (hero.z > my.z)) // player is above
         //    bottom of tower, and monster
      {
         pathSetNum = 2;
	 path_setter();
      }
			
      if((my.z >= 47) && (my.z <= 49)) // once on bottom of 
         //    tower, monster faces and runs toward player
      {
         path_set(my,NULL);
				 
         vec_set(temp.x, player.x);
         vec_sub(temp.x, my.x);
         vec_to_angle(my.pan, temp); // rotate the enemy towards the player
      }


With PathSetNum being toggled and filled.

please try this debug
Code:
action path_setter()
{
   VECTOR vec_next_node;

   path_set(my,"path_001");
	
   if(pathSetNum == 1)
   {
      my.NODE_NEXT=path_nextnode(my,1,1); // SET THE NODE
   }

   if(pathSetNum == 2)
   {	
      my.NODE_NEXT=4; // SET THE NODE
   }

   while(1)
   {

      // PATH NODE DETECTION AND FACING //////////////////////////////////
		
      if(vec_dist(my.x,vec_next_node.x) < 80) 
      {    
         if(pathSetNum == 1) 
         {
            my.NODE_NEXT=path_nextnode(my,my.NODE_NEXT,1); // Grab Next node on 
         }
	 if(pathSetNum == 2) 
	 {
	    my.NODE_NEXT-=1; // NODE GOES DOWN TO 3, BUT THEN JUMPS BACK UP TO 
                             //    4.
         }
      }
		
      path_getnode(my,my.NODE_NEXT,vec_next_node,NULL);  
         // Get next node - actual vector location
         // I BELIEVE THE ERROR IS HAPPENING HERE, PROBABLY WITH vec_next_node
	
      vec_to_angle(my.pan,vec_diff(NULL,vec_next_node,my.x)); // face the new 
                                                              //    node	
      
///////////
DEBUG_VAR(PathSetNum,500);
////////////////////////


wait(1);
   }
}



watch it flip-flop

Mal

Page 1 of 2 1 2

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