movement smoothing fix

git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2255 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
Lee Salzman
2008-07-29 22:42:07 +00:00
parent 41f4837b3e
commit cbf4983219
4 changed files with 33 additions and 21 deletions
+23 -17
View File
@@ -228,6 +228,28 @@ void movelocalplayer()
VARP(smoothmove, 0, 75, 100);
VARP(smoothdist, 0, 8, 16);
void predictplayer(playerent *d, bool move)
{
d->o = d->newpos;
d->yaw = d->newyaw;
d->pitch = d->newpitch;
if(move)
{
moveplayer(d, 1, false);
d->newpos = d->o;
}
float k = 1.0f - float(lastmillis - d->smoothmillis)/smoothmove;
if(k>0)
{
d->o.add(vec(d->deltapos).mul(k));
d->yaw += d->deltayaw*k;
if(d->yaw<0) d->yaw += 360;
else if(d->yaw>=360) d->yaw -= 360;
d->pitch += d->deltapitch*k;
}
d->lastpredict = lastmillis;
}
void moveotherplayers()
{
loopv(players) if(players[i] && players[i]->type==ENT_PLAYER)
@@ -242,23 +264,7 @@ void moveotherplayers()
}
if(d->state==CS_ALIVE || d->state==CS_EDITING)
{
if(smoothmove && d->smoothmillis>0)
{
d->o = d->newpos;
d->yaw = d->newyaw;
d->pitch = d->newpitch;
moveplayer(d, 1, false);
d->newpos = d->o;
float k = 1.0f - float(lastmillis - d->smoothmillis)/smoothmove;
if(k>0)
{
d->o.add(vec(d->deltapos).mul(k));
d->yaw += d->deltayaw*k;
if(d->yaw<0) d->yaw += 360;
else if(d->yaw>=360) d->yaw -= 360;
d->pitch += d->deltapitch*k;
}
}
if(smoothmove && d->smoothmillis>0) predictplayer(d, true);
else moveplayer(d, 1, false);
}
else if(d->state==CS_DEAD && lastmillis-d->lastpain<2000) moveplayer(d, 1, true);