Permalink
Browse files

Improve wallrunning physics.

Additionally, refactor the code to use the new vector library.
  • Loading branch information...
enneract committed Dec 20, 2015
1 parent ec08f93 commit abb451aa8b1ce74286b6517054008f2184421b1c
Showing with 32 additions and 64 deletions.
  1. +32 −64 src/shared/bg_pmove.cpp
@@ -1176,82 +1176,50 @@ PM_CheckWallRun
=============
*/
static bool PM_CheckWallRun()
{
vec3_t dir, movedir, point;
{

This comment has been minimized.

@Kangz

Kangz Dec 25, 2015

Member

Please, you can declare variables as you initialize them, we are not bound to C89 anymore.

int cost;
float jumpMag;
Vec3 forward, origin, velocity, normal;
vec3_t trace_end;
trace_t trace;
int cost = BG_Class( pm->ps->stats[ STAT_CLASS ] )->staminaJumpCost;

static const vec3_t refNormal = { 0.0f, 0.0f, 1.0f };
cost = BG_Class( pm->ps->stats[ STAT_CLASS ] )->staminaJumpCost;
jumpMag = BG_Class( pm->ps->stats[ STAT_CLASS ] )->jumpMagnitude;

// Make sure we can wall run
if ( !( BG_Class( pm->ps->stats[ STAT_CLASS ] )->abilities & SCA_WALLRUNNER ) )
{
return false;
}

// not enough stamina
if ( pm->ps->stats[ STAT_STAMINA ] < cost )
{
return false;
}
if ( pm->ps->pm_flags & PMF_RESPAWNED )
return false; // don't allow jump until all buttons are up

ProjectPointOnPlane( movedir, pml.forward, refNormal );
VectorNormalize( movedir );
if ( pm->cmd.upmove < 10 )
return false; // not holding jump

This comment has been minimized.

@Kangz

Kangz Dec 25, 2015

Member

At least indent this block ;-)


if ( pm->cmd.forwardmove < 0 )
{
VectorNegate( movedir, movedir );
}
if ( pm->ps->pm_flags & PMF_TIME_WALLJUMP )
return false;

//allow strafe transitions
if ( pm->cmd.rightmove )
{
ProjectPointOnPlane( movedir, pml.right, refNormal );
VectorNormalize( movedir );
// must wait for jump to be released
if ( pm->ps->pm_flags & PMF_JUMP_HELD && pm->ps->grapplePoint[ 2 ] == 1.0f )

This comment has been minimized.

@DolceTriade

DolceTriade Dec 20, 2015

Member

Is this correct? pm->ps->grapplePoint should be the trace plane normal, but you don't set that anywhere.

This comment has been minimized.

@DolceTriade

DolceTriade Dec 20, 2015

Member

Also, why shouldn't we be able to wallrun by holding jump? Feels much nicer and much closer to wallrunning.

return false;

if ( pm->cmd.rightmove < 0 )
{
VectorNegate( movedir, movedir );
}
}
if ( pm->ps->stats[ STAT_STAMINA ] < cost )
return false;

// trace into direction we are moving
VectorMA( pm->ps->origin, 0.25f, movedir, point );
pm->trace( &trace, pm->ps->origin, pm->mins, pm->maxs, point, pm->ps->clientNum,
pm->tracemask, 0 );
origin = Vec3::Load( pm->ps->origin );
forward = Vec3::Load( pml.forward );

if ( trace.fraction < 1.0f &&
!( trace.surfaceFlags & ( SURF_SKY | SURF_SLICK ) ) &&
trace.plane.normal[ 2 ] < MIN_WALK_NORMAL )
{
VectorCopy( trace.plane.normal, pm->ps->grapplePoint );
}
else
{
return false;
}
if ( pm->ps->pm_flags & PMF_RESPAWNED )
{
return false; // don't allow jump until all buttons are up
}
( origin + forward * 32 ).Store( trace_end );

This comment has been minimized.

@Kangz

Kangz Dec 25, 2015

Member

Better to do the following:
Vec3 traceEnd = ....
pm->trace(... traceEnd.Data() ...)

pm->trace( &trace, pm->ps->origin, pm->mins, pm->maxs, trace_end,
pm->ps->clientNum, pm->tracemask, 0);

if ( pm->cmd.upmove < 10 )
{
// not holding jump
if ( trace.fraction == 1.0f )
return false;
}

if ( pm->ps->pm_flags & PMF_TIME_WALLJUMP )
{
if ( trace.surfaceFlags & ( SURF_SKY | SURF_SLICK ) )
return false;
}

// must wait for jump to be released
if ( pm->ps->pm_flags & PMF_JUMP_HELD &&
pm->ps->grapplePoint[ 2 ] == 1.0f )
{
if ( trace.plane.normal[ 2 ] >= MIN_WALK_NORMAL )
return false;
}

pm->ps->pm_flags |= PMF_TIME_WALLJUMP;
pm->ps->pm_time = 200;
@@ -1261,14 +1229,14 @@ static bool PM_CheckWallRun()
pm->ps->pm_flags |= PMF_JUMP_HELD;

pm->ps->groundEntityNum = ENTITYNUM_NONE;

float NdotV = DotProduct( pm->ps->velocity, pm->ps->grapplePoint );
VectorScale( pm->ps->grapplePoint, 2 * NdotV, dir );
VectorSubtract( dir, pm->ps->velocity, pm->ps->velocity );
VectorNegate( pm->ps->velocity, pm->ps->velocity );
pm->ps->velocity[ 2 ] += BG_Class( pm->ps->stats[ STAT_CLASS ] )->jumpMagnitude;
pm->ps->stats[ STAT_STAMINA ] -= cost;

normal = Vec3::Load( trace.plane.normal );
velocity = Vec3::Load( pm->ps->velocity );

velocity += Math::Normalize( ( normal + Vec3(0,0,1) ) ) * jumpMag;

velocity.Store( pm->ps->velocity );
PM_AddEvent( EV_JUMP );
PM_PlayJumpingAnimation();

0 comments on commit abb451a

Please sign in to comment.