]> 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 bcbf6336e66e7a1ca7266a43aeaf328ee9ae99c5..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 nexttick;
        vector delta;
        vector veloc;
+       vector nextpos;
        if(time < self.animstate_endtime) {
                delta = self.destvec;
-               traveltime = self.animstate_endtime - self.animstate_starttime;
-               movephase = (time - self.animstate_starttime) / traveltime;
-
-               //bprint(ftos(movephase));
-               //bprint("\n");
-
-               // TODO: Don't mess with the velocity, instead compute where
-               // we want to be next tick and compute velocity from that
-
-               veloc = delta * (1/traveltime); // QuakeC doesn't allow vector/float division
-
-               // scale velocity with pi/2 so integrated over time we
-               // still have the original velocity
-               veloc = veloc * 1.5708;
-
-               // scale velocity with sin(phase)
-               phasepos = movephase * 3.1416; // phase * pi
-               phasepos = sin(phasepos);
-               veloc = veloc * phasepos;       
-
+               nexttick = time + sys_frametime;
+
+               if(nexttick < self.animstate_endtime) {
+                       traveltime = self.animstate_endtime - self.animstate_starttime;
+                       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 * (1 / sys_frametime); // so it arrives for the next frame
+
+               } else {
+                       veloc = self.finaldest - self.owner.origin;
+                       veloc = veloc * (1 / sys_frametime); // so it arrives for the next frame
+               }
                self.owner.velocity = veloc;
-               self.nextthink = time + 0.1;
+               self.nextthink = nexttick;
        } else {
                oldself = self;
                self.owner.think = self.think1;
@@ -248,6 +247,15 @@ void SUB_CalcMove (vector tdest, float tspeed, void() func)
                return;
        }
 
+       // 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;
+               return;
+       }
+
        controller = spawn();
        controller.classname = "SUB_CalcMove_controller";
        controller.owner = self;
@@ -259,14 +267,14 @@ void SUB_CalcMove (vector tdest, float tspeed, void() func)
        controller.think = SUB_CalcMove_controller_think;
        controller.think1 = self.think;
 
-       // let the controller handle the velocity compuation
-       //self.velocity = delta * (1/traveltime);       // QuakeC doesn't allow vector/float division
+       // the thinking is now done by the controller
        self.think = SUB_Null;
        self.nextthink = self.ltime + traveltime;
        
        // invoke controller
        self = controller;
        self.think();
+       self = self.owner;
 }
 
 void SUB_CalcMoveEnt (entity ent, vector tdest, float tspeed, void() func)