From edf220fc631408afd0453713cbc1e2c73c3dfc1e Mon Sep 17 00:00:00 2001 From: driAn Date: Sun, 11 Nov 2007 16:11:51 +0000 Subject: [PATCH] smooth recoil, crouching git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@1424 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/entity.h | 3 ++- source/src/hudgun.cpp | 3 +++ source/src/physics.cpp | 5 +++++ source/src/weapon.cpp | 18 ++++++++---------- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/source/src/entity.h b/source/src/entity.h index 96bdcd45..5ce607bc 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -90,6 +90,7 @@ struct physent { vec o, vel; // origin, velocity float yaw, pitch, roll; // used as vec in one place + float pitchvel; float maxspeed; // cubes per second, 24 for player int timeinair; // used for fake gravity float radius, eyeheight, aboveeye; // bounding box size @@ -99,7 +100,7 @@ struct physent char move, strafe; uchar state, type; - physent() : o(0, 0, 0), yaw(270), pitch(0), roll(0), maxspeed(16), + physent() : o(0, 0, 0), yaw(270), pitch(0), roll(0), pitchvel(0), maxspeed(16), radius(1.1f), eyeheight(4.5f), aboveeye(0.7f), state(CS_ALIVE), type(ENT_PLAYER) { diff --git a/source/src/hudgun.cpp b/source/src/hudgun.cpp index e9ce7585..1bc4cbb9 100644 --- a/source/src/hudgun.cpp +++ b/source/src/hudgun.cpp @@ -67,6 +67,7 @@ struct weaponmove if(percent_done > 100.0f) percent_done = 100.0f; // f(x) = -sin(x-1.5)^3 kick = -sinf(pow((1.5f/100.0f*percent_done)-1.5f,3)); + if(player1->crouching) kick *= 0.35f; } if(player1->lastaction && player1->lastattackgun==player1->gunselect) @@ -102,6 +103,8 @@ struct weaponmove sway.x *= swayspeed; sway.y *= swayspeed; sway.z *= swayupspeed; + + if(player1->crouching) sway.mul(0.35f); } pos.x -= base.x*k_back+sway.x; diff --git a/source/src/physics.cpp b/source/src/physics.cpp index 41b83087..bf4757e9 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -291,6 +291,11 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) d = pl->vel; d.mul(speed); + // smooth pitch + pl->pitch += pl->pitchvel*speed; + pl->pitchvel *= fpsfric-3; + pl->pitchvel /= fpsfric; + if(floating) // just apply velocity { pl->o.add(d); diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index c3a56d8b..b58a00cc 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -662,18 +662,16 @@ void raydamage(vec &from, vec &to, playerent *d) } } +VAR(testrecoil, 0, 100, 200); + void spreadandrecoil(vec &from, vec &to, playerent *d) { - //nothing special for a knife - if(d->gunselect==GUN_KNIFE || d->gunselect==GUN_GRENADE) return; + if(d->gunselect==GUN_KNIFE || d->gunselect==GUN_GRENADE) return; //nothing special for a knife - //spread vec unitv; float dist = to.dist(from, unitv); float f = dist/1000; int spd = guns[d->gunselect].spread; - - //recoil float rcl = guns[d->gunselect].recoil*-0.01f; if(d->gunselect==GUN_ASSAULT) @@ -683,7 +681,7 @@ void spreadandrecoil(vec &from, vec &to, playerent *d) rcl += (rnd(8)*-0.01f); } - if((d->gunselect==GUN_SNIPER) /*&& (d->vel.x<.25f && d->vel.y<.25f)*/ && scoped) + if((d->gunselect==GUN_SNIPER) && scoped) { spd = 1; rcl = rcl / 3; @@ -697,10 +695,10 @@ void spreadandrecoil(vec &from, vec &to, playerent *d) #undef RNDD } - //increase pitch for recoil - d->vel.add(vec(unitv).mul(rcl/dist)); - - if(d->pitch<80.0f) d->pitch += guns[d->gunselect].recoil*0.05f; + //increase pitch for recoil + d->vel.add(vec(unitv).mul(rcl/dist).mul(d->crouching ? 0.5 : 1.0f)); + if(d->pitch < 80.0f) d->pitchvel += guns[d->gunselect].recoil*0.15f*(float)testrecoil/100.0f; + //if(d->pitch<80.0f) d->pitch += guns[d->gunselect].recoil*0.05f; } bool hasammo(playerent *d) // bot mod