Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (ozgur, EternallyCurious, howardR, 1 invisible), 623 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Dragon with the jitters #471326
02/28/18 05:25
02/28/18 05:25
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
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.
Re: Dragon with the jitters [Re: Ruben] #471333
02/28/18 10:17
02/28/18 10:17
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
that happens because the constant turning speed makes the dragon pass by the goal when the angle between them is smaller than the applied turning angle.

Imagine the dragon pan is 10, the goal angle is 0 and time_step is 1. The sequence of dragosn pan is:
10 (-4)
6 (-4)
2 (-4)
-2 (+4) <-- jitter start. It pass by the goal
2 (-4) <-- it pass by the goal again but in opposite direction
-2 (+4) <-- same thing again and again...

Code:
var nTurnAngle = DRAGON_TURNING_SPEED * time_step;
my.pan += clamp(ang(vTargetAngle.pan - my.pan), -nTurnAngle, nTurnAngle);


Re: Dragon with the jitters [Re: txesmi] #471359
03/01/18 02:46
03/01/18 02:46
Joined: Jun 2010
Posts: 590
California
Ruben Offline OP
User
Ruben  Offline OP
User

Joined: Jun 2010
Posts: 590
California
Thank you Txesmi! It worked perfectly. Sorry I am asking these questions. They are of the last few errors I have in my game that have been hanging on me for months. Again, thank you. :-)

Last edited by Ruben; 03/01/18 03:40.

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