vec_dist

Posted By: Ruben

vec_dist - 01/24/17 11:33

I am trying to have my game program tell me the vector distance between the player and a giant enemy scorpion model using this code:

Code:
DEBUG_VAR(scorpionPlyrDist, 100);
...
scorpionPlyrDist = vec_dist (hero.x, my.x);



I have it working for other enemy models, but strangely it is not working for the giant scorpion model.

Here is my code to try and make this happen:

Code:
action scorpion_action()
{
   my.eflags |= FAT | NARROW;

   ...

   demo_scorpion = me;
	
   my.push = 10;
	
   ...

   set(my, POLYGON);

   my.status = scorpion_unaware;

   while (my.status != scorpion_dead) 
   {
      DEBUG_VAR(scorpionPlyrDist, 100); // scorpionPlyrDist
         //    IS ALWAYS EQUALING 0, INSTEAD OF CHANGING AS 
         //    THE PLAYER MOVES CLOSER TO THE GIANT SCORPION.

      ...

      while(1) // I DO NOT KNOW WHY I NEED THIS EXTRA LOOP TO 
               //    MAKE THIS ANIMATION HAPPEN.  I DO NOT 
               //    NEED THIS EXTRA LOOP TO MAKE THIS 
               //    ANIMATION WORK FOR OTHER MODELS.
      {
         my.ANIMATION += 2*time_step;	  
         ent_animate(me,"stand",my.ANIMATION,ANM_CYCLE);
         
         wait(1);
      }

      if(scrpn_health <= 0)
      {
         my.status = scorpion_dead;
      }
	
      scorpionPlyrDist = vec_dist (hero.x, my.x); // FOR SOME
         //    REASON, scorpionPlyrDist IS ALWAYS EQUALING 0,
         //    ACCORDING TO THE DEBUG_VAR UP ABOVE, NO MATTER 
         //    HOW CLOSE THE PLAYER GETS TO THE GIANT SCORPION.
   	
      c_scan(my.x,my.pan,vector(360,0,750),SCAN_ENTS | 
         SCAN_FLAG2 | IGNORE_ME);

      if(you)
      {	
         // SCORPION DETECTING PLAYER CODE.
         ...
			
         wait (1);
      }
  
      my.tilt = 0;
	
      if(my.status == scorpion_dead)
      {
         // SCORPION DYING CODE
         ...	
      }
      
      set (my, PASSABLE); // allow the player to pass through 
                          //    the corpse now
}


I used this method for a goblin entity I have, and it is working for the goblin, but not for the scorpion, strangely.

(1) Anyone know why scorpionPlyrDist is always equaling 0, and not showing the vector distance in real time between the giant scorpion and the player? Even if I get rid the while(1) loop, I get the same result.

(2) Does anyone also know why I need the while(1) loop within the while(my.status != scorpion_dead) loop to make the "stand" animation for the scorpion work? I did not need the while(1) loop in a separate goblin code to make it work for the goblin.

Posted By: Reconnoiter

Re: vec_dist - 01/24/17 16:59

Hi,

Some parts of your code are confusing which is probably why you have some bugs in it. First of, what is 'my.status'? A defined skill? Something like my.STATE would be more clearer I think.
Also remove the 2nd while, and place the animation code in the first while. Because now only code in your 2nd while is running every frame. Now you mention that than the anim code is not running properly in the 1st while, my quess this is because either you have some 'break;' that breaks the while loop OR 'my.status' is not equal to 'scorpion_dead' and so the 1st while stops running.
So debug both my.status and scorpion_dead every frame and see what happens with them.
Also there is no wait(1); for the 1st loop.
Posted By: Ruben

Re: vec_dist - 01/25/17 06:41

Sadly, I apologize. I did not quite accurately record the code the way my program was completely in my original post. There was actually a "wait(1)" in my first while loop. I ended up fixing it so that the scorpion initiates the "stand" animation by setting its health over 0 in the "main" file. Because I never set it over 0 in the main file, scrpn_health kept equaling 0, and never initiating the "while (my.status != scorpion_dead)" code, since my.status was equal to scorpion_dead.
Posted By: Reconnoiter

Re: vec_dist - 01/25/17 09:56

What I do in these circumstances is placing error("<fitting description>"); over the place and see which error(); triggers and which not. laugh
© 2024 lite-C Forums