Experimental Unreal-style view bob.

This commit is contained in:
Mari the Deer 2022-11-24 12:48:52 +01:00
commit b9698e1aaa
4 changed files with 112 additions and 48 deletions

View file

@ -1,3 +1,3 @@
[default]
SWWM_MODVER="\cyDEMOLITIONIST \cw1.3pre r629 \cu(Tue 22 Nov 23:05:20 CET 2022)\c-";
SWWM_SHORTVER="\cw1.3pre r629 \cu(2022-11-22 23:05:20)\c-";
SWWM_MODVER="\cyDEMOLITIONIST \cw1.3pre r631 \cu(Thu 24 Nov 12:49:11 CET 2022)\c-";
SWWM_SHORTVER="\cw1.3pre r631 \cu(2022-11-24 12:49:11)\c-";

Binary file not shown.

Binary file not shown.

View file

@ -123,6 +123,8 @@ Class Demolitionist : PlayerPawn
SWWMShadow myshadow;
double bobtime, oldbobtime, oldbob;
Default
{
Tag "$T_DEMOLITIONIST";
@ -1060,50 +1062,6 @@ Class Demolitionist : PlayerPawn
else player.fov += zoom;
}
}
override Vector2 BobWeapon( double ticfrac )
{
// non-mod weapons bob normally
if ( !(player.ReadyWeapon is 'SWWMWeapon') )
return Super.BobWeapon(ticfrac);
bool oldbob = !!(player.WeaponState&WF_WEAPONBOBBING);
player.WeaponState |= WF_WEAPONBOBBING; // always bob
Vector2 cur = Super.BobWeapon(ticfrac);
if ( !oldbob ) player.WeaponState &= ~WF_WEAPONBOBBING;
double fangle = SWWMUtility.Lerp(oldangle,angle,ticfrac);
double fpitch = SWWMUtility.Lerp(oldpitch,pitch,ticfrac);
double flagangle = SWWMUtility.Lerp(oldlagangle,lagangle,ticfrac);
double flagpitch = SWWMUtility.Lerp(oldlagpitch,lagpitch,ticfrac);
double diffang = fangle-flagangle;
double diffpitch = fpitch-flagpitch;
if ( abs(diffang) > 1. )
{
int sgn = (diffang>0)?1:-1;
diffang = abs(diffang)**.7*sgn;
}
if ( abs(diffpitch) > 1. )
{
int sgn = (diffpitch>0)?1:-1;
diffpitch = abs(diffpitch)**.7*sgn;
}
Vector3 flagvel = SWWMUtility.LerpVector3(oldlagvel,lagvel,ticfrac);
double diffx = flagvel dot SWWMUtility.AngleToVector3(flagangle+90);
double diffy = flagvel dot (0,0,1);
if ( abs(diffx) > 1. )
{
int sgn = (diffx>0)?1:-1;
diffx = abs(diffx)**.5*sgn;
}
if ( abs(diffy) > 1. )
{
int sgn = (diffy>0)?1:-1;
diffy = abs(diffy)**.5*sgn;
}
cur.x += diffang;
cur.y -= diffpitch;
cur.x += diffx*4.;
cur.y += diffy*4.;
return cur*SWWMUtility.Lerp(oldlagready,lagready,ticfrac);
}
override void PlayerThink()
{
oldangle = angle;
@ -1978,10 +1936,115 @@ Class Demolitionist : PlayerPawn
}
override void CalcHeight()
{
Super.CalcHeight();
double defviewh = viewheight+player.crouchviewdelta;
oldbob = player.bob;
if ( bFlyCheat || (player.cheats&CF_NOCLIP2) )
player.bob = 0.;
else
player.bob = min((player.vel dot player.vel)*player.GetMoveBob(),MAXBOB);
if ( player.cheats&CF_NOVELOCITY )
{
player.viewz = pos.z+defviewh;
if ( player.viewz > ceilingz-4 )
player.viewz = ceilingz-4;
SetViewPos((0.,0.,0.));
return;
}
// adjust viewheight
if ( player.playerstate == PST_LIVE )
{
player.viewheight += player.deltaviewheight;
if ( player.viewheight > defviewh )
{
player.viewheight = defviewh;
player.deltaviewheight = 0.;
}
else if ( player.viewheight < (defviewh/2.) )
{
player.viewheight = defviewh/2.;
if ( player.deltaviewheight <= 0. )
player.deltaviewheight = 1./65536.;
}
if ( player.deltaviewheight )
{
player.deltaviewheight += .25;
if ( !player.deltaviewheight )
player.deltaviewheight = 1./65536.;
}
}
// apply bobbing (formula adapted from Unreal)
oldbobtime = bobtime;
double vel2d = vel.xy.length();
if ( vel2d < .25 ) bobtime += .2/GameTicRate;
else bobtime += (.3+.7*min(vel2d/8.,4.))/GameTicRate;
Vector2 bob = (sin(bobtime*180.),sin(bobtime*360.))*player.bob*.25;
if ( player.morphtics )
bob = (0.,0.);
// set up viewz
player.viewz = pos.z+player.viewheight+(bob.y*clamp(viewbob,0.,1.5));
// handle smooth step down (hacky but looks ok)
player.viewz += ssup;
ssup = max(0,(ssup*.7)-.25);
if ( floorclip && (player.playerstate != PST_DEAD) && (pos.z <= floorz) )
player.viewz -= floorclip;
if ( player.viewz > ceilingz-4 )
player.viewz = ceilingz-4;
if ( player.viewz < floorz+4 )
player.viewz = floorz+4;
// add viewpos Y for side bob
SetViewPos((0.,bob.x*clamp(viewbob,0.,1.5),0.));
}
private Vector2 BobWeaponAngle( double ticfrac )
{
// bob with player view
Vector2 prevbob = (-sin(oldbobtime*180.),.5*abs(sin(oldbobtime*180.)))*oldbob*.25;
Vector2 bob = (-sin(bobtime*180.),.5*abs(sin(bobtime*180.)))*player.bob*.25;
double bobstr = (player.WeaponState&WF_WEAPONBOBBING)?1.:player.GetWBobFire();
return SWWMUtility.LerpVector2(prevbob,bob,ticfrac)*bobstr*clamp(viewbob,0.,1.5);
}
override Vector2 BobWeapon( double ticfrac )
{
// non-mod weapons bob normally
if ( !(player.ReadyWeapon is 'SWWMWeapon') )
return Super.BobWeapon(ticfrac);
bool oldbob = !!(player.WeaponState&WF_WEAPONBOBBING);
player.WeaponState |= WF_WEAPONBOBBING; // always bob
Vector2 cur = BobWeaponAngle(ticfrac);
if ( !oldbob ) player.WeaponState &= ~WF_WEAPONBOBBING;
double fangle = SWWMUtility.Lerp(oldangle,angle,ticfrac);
double fpitch = SWWMUtility.Lerp(oldpitch,pitch,ticfrac);
double flagangle = SWWMUtility.Lerp(oldlagangle,lagangle,ticfrac);
double flagpitch = SWWMUtility.Lerp(oldlagpitch,lagpitch,ticfrac);
double diffang = fangle-flagangle;
double diffpitch = fpitch-flagpitch;
if ( abs(diffang) > 1. )
{
int sgn = (diffang>0)?1:-1;
diffang = abs(diffang)**.7*sgn;
}
if ( abs(diffpitch) > 1. )
{
int sgn = (diffpitch>0)?1:-1;
diffpitch = abs(diffpitch)**.7*sgn;
}
Vector3 flagvel = SWWMUtility.LerpVector3(oldlagvel,lagvel,ticfrac);
double diffx = flagvel dot SWWMUtility.AngleToVector3(flagangle+90);
double diffy = flagvel dot (0,0,1);
if ( abs(diffx) > 1. )
{
int sgn = (diffx>0)?1:-1;
diffx = abs(diffx)**.5*sgn;
}
if ( abs(diffy) > 1. )
{
int sgn = (diffy>0)?1:-1;
diffy = abs(diffy)**.5*sgn;
}
cur.x += diffang;
cur.y -= diffpitch;
cur.x += diffx*4.;
cur.y += diffy*4.;
return cur*SWWMUtility.Lerp(oldlagready,lagready,ticfrac);
}
override void CheckPitch()
{
@ -2128,7 +2191,8 @@ Class Demolitionist : PlayerPawn
else
{
vel.xy += RotateVector(nmove,angle);
player.vel += RotateVector(nmove,angle)*bobfactor*16.;
if ( player.onground ) player.vel += RotateVector(nmove,angle)*bobfactor*16.;
else player.vel *= .75;
}
// override air control because we REALLY need the extra mobility
if ( !player.onground && !bNOGRAVITY )