Skip to content

Commit

Permalink
Step-up only when trackpad is used to reduce jitter (maybe do step-up…
Browse files Browse the repository at this point in the history
… when a distance threshold has been passed)
  • Loading branch information
veryjos committed Nov 28, 2016
1 parent 4442d72 commit d6ccddc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
2 changes: 2 additions & 0 deletions HPL1Engine/include/physics/CharacterBody.h
Expand Up @@ -60,6 +60,7 @@ namespace hpl {
cVector3f mvNormal;
bool mbCollide;
bool mbIsPlayer;
bool mbIsStatic;
};

//------------------------------------------------
Expand Down Expand Up @@ -348,6 +349,7 @@ namespace hpl {

cVector3f vr_velocity;
bool vr_skipnextupdate;
bool vr_stepstaticonly;

protected:

Expand Down
41 changes: 25 additions & 16 deletions HPL1Engine/sources/physics/CharacterBody.cpp
Expand Up @@ -147,6 +147,7 @@ namespace hpl {

vr_velocity = cVector3f(0.0f, 0.0f, 0.0f);
vr_skipnextupdate = false;
vr_stepstaticonly = false;

SetIsPlayer(false);
}
Expand Down Expand Up @@ -183,6 +184,8 @@ namespace hpl {
{
mfMinDist = 10000.0f;
mbCollide = false;
mbIsStatic = false;
mvNormal.x = mvNormal.y = mvNormal.z = 0.0f;
}

//-----------------------------------------------------------------------
Expand All @@ -198,6 +201,7 @@ namespace hpl {
mfMinDist = apParams->mfDist;
mvNormal = apParams->mvNormal;
mbCollide = true;
mbIsStatic = pBody->GetMass() == 0.0f;
}

return true;
Expand Down Expand Up @@ -878,24 +882,29 @@ namespace hpl {
mpWorld->CastRay(mpRayCallback, start, end, true, true, false);

if (mpRayCallback->mbCollide) {
float stepHeight = mpBody->GetShape()->GetSize().y - mpRayCallback->mfMinDist;
cVector3f normal = mpRayCallback->mvNormal;

if (stepHeight <= mfMaxStepHeight) {
if (normal.y >= 0.5f && !(stepHeight <= 0.0f)) {
cVector3f stepPos = wantPos + cVector3f(0.0f, stepHeight, 0.0f) + vMoveDir * (epsilon * i);
cVector3f checkPos;

mpWorld->CheckShapeWorldCollision(&checkPos, mpBody->GetShape(),
cMath::MatrixTranslate(stepPos), mpBody,
false, true, NULL, mbCollideCharacter, false, mbCollidePlayer, mbIsPlayer);

if (stepPos == checkPos) {
mvPosition = stepPos;
if ((vr_stepstaticonly && mpRayCallback->mbIsStatic) || !vr_stepstaticonly) {
float stepHeight = mpBody->GetShape()->GetSize().y - mpRayCallback->mfMinDist;
cVector3f normal = mpRayCallback->mvNormal;

if (stepHeight <= mfMaxStepHeight) {
if (normal.y >= 0.5f && !(stepHeight <= 0.0f)) {
cVector3f stepPos = wantPos + cVector3f(0.0f, stepHeight, 0.0f) + vMoveDir * (epsilon * i);
cVector3f checkPos;

if (fabs(stepPos.y - mvPosition.y) > mfMaxStepHeight)
continue;

mpWorld->CheckShapeWorldCollision(&checkPos, mpBody->GetShape(),
cMath::MatrixTranslate(stepPos), mpBody,
false, true, NULL, mbCollideCharacter, false, mbCollidePlayer, mbIsPlayer);

if (stepPos == checkPos) {
mvPosition = stepPos;
}
}
}

break;
break;
}
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion PenumbraOverture/Player.cpp
Expand Up @@ -1040,7 +1040,7 @@ void cPlayer::OnWorldLoad()

mpCharBody->SetMaxGravitySpeed(40.0f);
mpCharBody->SetCustomGravityActive(true);
mpCharBody->SetCustomGravity(cVector3f(0,-18.0f,0));
mpCharBody->SetCustomGravity(cVector3f(0,-10.0f,0));

mpCharBody->SetMaxPushMass(mpInit->mpGameConfig->GetFloat("Player","MaxPushMass",1));
mpCharBody->SetPushForce(mpInit->mpGameConfig->GetFloat("Player","PushForce",1));
Expand Down Expand Up @@ -1478,7 +1478,9 @@ void cPlayer::Update(float afTimeStep)

mpCharBody->vr_velocity = bodyDelta;

mpCharBody->vr_stepstaticonly = true;
mpCharBody->Update(afTimeStep);
mpCharBody->vr_stepstaticonly = false;
}

// Now add input movement
Expand Down

0 comments on commit d6ccddc

Please sign in to comment.