2 paths interferring?

Posted By: Ruben

2 paths interferring? - 11/10/15 05:12

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?
Posted By: Ruben

Re: 2 paths interferring? - 11/13/15 02:06

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

Re: 2 paths interferring? - 11/13/15 03:18

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

Posted By: Ruben

Re: 2 paths interferring? - 11/14/15 21:06

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

Re: 2 paths interferring? - 11/14/15 21:38

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

Posted By: Anonymous

Re: 2 paths interferring? - 11/14/15 22:48

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
Posted By: Ruben

Re: 2 paths interferring? - 11/15/15 11:28

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

Re: 2 paths interferring? - 11/15/15 18:20

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

Posted By: Ruben

Re: 2 paths interferring? - 11/15/15 20:12

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

Re: 2 paths interferring? - 11/15/15 20:24

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

Re: 2 paths interferring? - 11/15/15 20:26

LOL--- It's your c_scan -monster see the player and sets pathSetNum back to 1 then calls path_setter()
Posted By: Anonymous

Re: 2 paths interferring? - 11/15/15 20:34

Also this path_Set() should not be there

Code:
if((my.z >= 47) && (my.z <= 49)) // once on bottom of 
         //    tower, monster faces and runs toward player
      {
         path_set(my,NULL);



My quote from days ago
Quote:

LOL are you detaching when you reach node 2 by calling path_set(my,NULL);
to many times?
Posted By: Anonymous

Re: 2 paths interferring? - 11/15/15 20:38

Anyways - I'm getting burned out on this topic. Once again it would have just been easier for my to rewrite the whole code on day of the post.

Mal
Posted By: Ruben

Re: 2 paths interferring? - 11/16/15 08:00

Wow, the code is improving, but acting awfully strange.

So, when the game starts, the monster is standing 30 feet up in the air on the spiral staircase, and if the player walks toward the monster on the bottom ground of the tower to where the monster detects the player by c_scan(), the monster will run down path_001 to the bottom of the tower. The monster will then turn and face the player, and run toward the player. If the player dodges the monster and runs past it, and then runs up the stairs, the monster will run toward node 4 on the bottom of the spiral staircase, but then stop there while jittering between nodes 3 and 4.

At this time, the player has run up the spiral staircase a little ways, turns around, and is looking down at the monster on the tower floor, jittering like it does. While the player looks at the monster, the monster is not moving past node 4. However, when the player walks off the side of the spiral staircase and lands on the tower floor 30 feet below, the monster starts running up the spiral staircase on path_001 PERFECTLY with no jittering!

This is the code that is making this happen:

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; 
               
            if(my.NODE_NEXT < 1)
            {
               my.NODE_NEXT = 1;	
	    }
         }
      }
		
      path_getnode(my,my.NODE_NEXT,vec_next_node,NULL);  
         
      vec_to_angle(my.pan,vec_diff(NULL,vec_next_node,my.x));
         // face the new node

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

action monster_action() 
{
   ...

   pathSetNum = 1;

   ...
	
   while (1)
   { 
      ...
	   
      if(my.STATE == 1) 
      {	
         my.ANIMATION += 3*time_step;
			
         ent_animate(me,"idle",my.ANIMATION,ANM_CYCLE);	
		
         c_scan(my.x,my.pan,vector(360,0,750),SCAN_ENTS | SCAN_FLAG2 | 
            IGNORE_ME);
			
	 if (you) // player detected?
	 {  
	    path_setter(); // MONSTER RUNS DOWN path_001 SINCE pathSetNum = 1
					
	    ...

	    my.STATE = 2; 
	    
            ...
	 }				
      }
	
      // state 2: turn towards enemy, cast spells /////////////////// 
      if (my.STATE == 2) 
      {				
         if((hero.z > 50) && (hero.z > my.z)) // IF PLAYER IS HIGHER THAN 
                                              //    MONSTER ON STAIRS
	 {
	    pathSetNum = 2;
				
	    my.NODE_NEXT = 4;
	 }

         if((my.z >= 47) && (my.z <= 49))
	 {
	    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);
   }
}



I tried taking this code out:

Code:
if((my.z >= 47) && (my.z <= 49))
{
   vec_set(temp.x, player.x);
   vec_sub(temp.x, my.x);
   vec_to_angle(my.pan, temp); // rotate the enemy towards the player
}



...thinking it might have been somehow interfering, but the same result happened even after commenting it out.

It is crazy trying to debug this, but fun at the same time. :-)
Posted By: Anonymous

Re: 2 paths interferring? - 11/16/15 08:35

only one part is left that is influenced by the player location
Code:
if((hero.z > 50) && (hero.z > my.z)) // IF PLAYER IS HIGHER THAN 
                                              //    MONSTER ON STAIRS
	 {
	    pathSetNum = 2;
				
	    my.NODE_NEXT = 4;
	 }


This rest to node 4 very time the player is ABOVE the mosnster... Can't believe I didn't see it before

Just do this
Code:
if((hero.z > 50) && (hero.z > my.z)) // IF PLAYER IS HIGHER THAN 
                                              //    MONSTER ON STAIRS
	 {
	    pathSetNum = 2;
				
	   // my.NODE_NEXT = 4;
	 }


and this ...

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; 
               
            if(my.NODE_NEXT < 1)
            {
               my.NODE_NEXT = 1;	
	    }
         }
      }
		
      path_getnode(my,my.NODE_NEXT,vec_next_node,NULL);  
         
      vec_to_angle(my.pan,vec_diff(NULL,vec_next_node,my.x));
         // face the new node

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


EDIT --- REALY REALLY need sleep. Have fun man.
lol... I need sleep
Mal
Posted By: Ruben

Re: 2 paths interferring? - 11/16/15 08:47

Only problem with that, is that now the monster is skipping nodes 4 and/or 3, and running straight in the air towards node 2 again.
Posted By: Ruben

Re: 2 paths interferring? - 11/16/15 09:13

So, for some reason, this code does not do what it is supposed to do as it is being executed:

Code:
if((hero.z > 50) && (hero.z > my.z)) // IF PLAYER IS HIGHER THAN 
                                              //    MONSTER ON STAIRs
{
   beep();

   pathSetNum = 2;
				
   my.NODE_NEXT = 4; // WITHOUT THIS HERE, THE MONSTER SKIPS NODES 4 AND/OR 3,
                     //    AND RUNS STRAIGHT TO NODE 2 THROUGH THE AIR.
}


When the player is above the monster on the z axis by being higher up on the spiral staircase, it is beeping like crazy. However, the monster does not move beyond node 4, and jitters between nodes 3 and 4. When the player walks off the side of the spiral staircase, the beeping stops, but then the monster starts walking up path_001 like its supposed to.

It is strange how the above code does not execute while it is happening, but executes after it happened.
Posted By: Anonymous

Re: 2 paths interferring? - 11/16/15 10:57

Every time you hear the beep you also RESET my.NODE_NEXT back to 4 even though the function ran past 4 and has set it to 3 ...

Will do a lock/check with a new var.

Code:
action monster_action() 
{
var set_once =0; // Attention <-NEW VAR
   ...

   pathSetNum = 1;

   ...
	
   while (1)
   { 
      ...
	   
      if(my.STATE == 1) 
      {	
         my.ANIMATION += 3*time_step;
			
         ent_animate(me,"idle",my.ANIMATION,ANM_CYCLE);	
		
         c_scan(my.x,my.pan,vector(360,0,750),SCAN_ENTS | SCAN_FLAG2 | 
            IGNORE_ME);
			
	 if (you) // player detected?
	 {  
	    path_setter(); // MONSTER RUNS DOWN path_001 SINCE pathSetNum = 1
					
	    ...

	    my.STATE = 2; 
	    
            ...
	 }				
      }
	
      // state 2: turn towards enemy, cast spells /////////////////// 
      if (my.STATE == 2) 
      {				
         if((hero.z > 50) && (hero.z > my.z)) // IF PLAYER IS HIGHER THAN 
                                              //    MONSTER ON STAIRS
	 {
	    pathSetNum = 2;
		if(!set_once)
           {		
	    my.NODE_NEXT = 4;
            set_once=1;
           }
	 }

         if((my.z >= 47) && (my.z <= 49))
	 {
	    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);
   }
}

Posted By: Ruben

Re: 2 paths interferring? - 11/16/15 12:29

Cool! That worked. Now I need to play with this system to make it behave in the artificially intelligent way that it needs to. Thank you so much Malice. This is big for me.

By the way, I sent you a PM. :-)
© 2024 lite-C Forums