diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2015-04-12 02:32:12 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2015-04-12 02:32:12 +0200 |
commit | 622ecb7bedeacaf4063dadc87764d3b66ad2f009 (patch) | |
tree | 6a936666d9d495d59bb7a0cc294b1077213550fe /src/game/bg_pmove.c | |
parent | eca487d693704aed6beb821222481724f3aeedd4 (diff) |
Make force fields apply forces smoothly and continuously.
Diffstat (limited to 'src/game/bg_pmove.c')
-rw-r--r-- | src/game/bg_pmove.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/game/bg_pmove.c b/src/game/bg_pmove.c index ecdaccf..b19dd68 100644 --- a/src/game/bg_pmove.c +++ b/src/game/bg_pmove.c @@ -3901,6 +3901,45 @@ void PM_UpdateViewAngles( playerState_t *ps, const usercmd_t *cmd ) } } +/* +================ +PM_ForceFields +================ +*/ + +void PM_ForceFields( void ) +{ + int i; + float dt = pml.msec * 0.001f; + forceField_t *ff; + vec3_t total = { 0 }; + + for( i = 0; i < pm->numForceFields; i++ ) + { + vec3_t delta; + float distance, force; + trace_t tr; + + ff = pm->forceFields + i; + + VectorSubtract( ff->origin, pm->ps->origin, delta ); + distance = VectorNormalize( delta ); + + if( distance > ff->range ) + continue; + + pm->trace( &tr, pm->ps->origin, NULL, NULL, ff->origin, pm->ps->clientNum, MASK_SOLID ); + + if( tr.fraction < 1.0f ) + continue; + + force = ff->force / distance * ( 1.0f - distance / ff->range ); + + VectorMA( total, force, delta, total ); + } + + VectorMA( pm->ps->velocity, dt, total, pm->ps->velocity ); +} /* ================ @@ -4062,6 +4101,8 @@ void PmoveSingle( pmove_t *pmove ) PM_DropTimers( ); + PM_ForceFields( ); + if( pm->ps->pm_type == PM_JETPACK ) PM_JetPackMove( ); else if( pm->ps->pm_type == PM_HUMMEL ) |