]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/g_subs.qc
make the SUB_CalcMove controller think every frame. This increases smoothness and...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / g_subs.qc
index 88e5fa1fd366d16bff86eedf6febecbff546be26..fe7a7e29f0feb44bf5ccc49b98eae106b182f286 100644 (file)
@@ -180,35 +180,34 @@ void SUB_CalcMoveDone (void)
 void SUB_CalcMove_controller_think (void)
 {
        entity oldself;
-       float movephase;
        float traveltime;
        float phasepos;
-       float remaining;
+       float nexttick;
        vector delta;
        vector veloc;
        vector nextpos;
        if(time < self.animstate_endtime) {
                delta = self.destvec;
+               nexttick = time + sys_frametime;
 
-               if((time + 0.1) < self.animstate_endtime) {
-
+               if(nexttick < self.animstate_endtime) {
                        traveltime = self.animstate_endtime - self.animstate_starttime;
-                       movephase = ((time + 0.1) - self.animstate_starttime) / traveltime;
-                       phasepos = sin(movephase * 3.14159265 / 2);
+                       phasepos = (nexttick - self.animstate_starttime) / traveltime; // range: [0, 1]
+                       phasepos = 3.14159265 + (phasepos * 3.14159265); // range: [pi, 2pi]
+                       phasepos = cos(phasepos); // cos [pi, 2pi] is in [-1, 1]
+                       phasepos = phasepos + 1; // correct range to [0, 2]
+                       phasepos = phasepos / 2; // correct range to [0, 1]
                        nextpos = self.origin + (delta * phasepos);
 
                        veloc = nextpos - self.owner.origin;
-                       veloc = veloc * 10; // so it arrives in 0.1 seconds
-                       self.nextthink = time + 0.1;
+                       veloc = veloc * (1 / sys_frametime); // so it arrives for the next frame
+
                } else {
-                       remaining = self.animstate_endtime - time;
                        veloc = self.finaldest - self.owner.origin;
-                       veloc = veloc * (1 / remaining); // so it'll arrive in the remaining time
-                       self.nextthink = self.animstate_endtime;
+                       veloc = veloc * (1 / sys_frametime); // so it arrives for the next frame
                }
-
                self.owner.velocity = veloc;
-
+               self.nextthink = nexttick;
        } else {
                oldself = self;
                self.owner.think = self.think1;
@@ -248,9 +247,9 @@ void SUB_CalcMove (vector tdest, float tspeed, void() func)
                return;
        }
 
-       // the controller only thinks every 0.1 seconds, so very short
-       // animations should just use the traditional movement
-       if (traveltime < 0.3)
+       // very short animations don't really show off the effect
+       // of controlled animation, so let's just use linear movement
+       if (traveltime < 0.15)
        {
                self.velocity = delta * (1/traveltime); // QuakeC doesn't allow vector/float division
                self.nextthink = self.ltime + traveltime;