I have a dragon in my game.

If the player gets within a certain distance of the dragon, the dragon steadily pan turns toward the player (as if it is now alerted by the player), and shoots fireballs from its mouth toward the player.

The problem is that once the dragon's mouth and body faces the player, it seems to slightly pan wiggle very fast while it shoots its fireballs toward the player, making its face look blurry. It is more cosmetic than anything, since the fireballs are accurately hitting their target (the player). It just looks silly that the dragon is slightly pan wiggling while firing toward the player.

In the past, I had code that made it so that once the dragon was alerted to the player's presence, its body would just immediately face the player, without a progressive turning movement. The dragon did not have the jitters with this method, but it just looked silly that the dragon would not progressively turn toward the player, but warp turn (instantly face the player without turning). Here is that code:

Code:
vec_set(temp.x, player.x);
vec_sub(temp.x, my.x);
vec_to_angle(my.pan,temp);


I like the code I have now, because it allows a progressive turning movement by the dragon, instead of its body instantly facing the player (which is what the last code above does). However, after it smoothly and progressively pan turns toward the player, once it faces the player and shoots its fireballs toward the player, it gets the jitter bug, and slightly pan wiggles very fast, making its face look blurry while it is shooting.

Here is the code I am using right now that is making this happen:

Code:
action dragon_action() 
{
   ...

   VECTOR vDirection;
   ANGLE vTargetAngle;

   ...

   while (my.status != dead) 
   {
      vec_diff(vDirection,hero.x,my.x); // I believe the jitter
      vec_to_angle(vTargetAngle,vDirection); //    disease is here.

      ...

      my.pan += 4 * (time_step * sign(ang(vTargetAngle.pan -
         my.pan))); 
			
      my.ANIMATION += 3*time_step;
      ent_animate(me,"attack",my.ANIMATION,ANM_CYCLE);

      ...

      wait(1);
   }
}



Can anyone give me a clue on how to cure the dragon of its jitters (what I am doing wrong in my code that causes this jittery effect in the dragon), while still allowing it to make progressive pan moving turns toward the player when it attacks?

Last edited by Ruben; 02/28/18 05:58.