Move fall height reset into PhysicsSystem (Fixes #4049)

To avoid using onGround before it's actually set.
pull/292/head
scrawl 7 years ago
parent a560841705
commit fcb815f2c7

@ -1704,20 +1704,11 @@ void CharacterController::update(float duration)
if(sneak || inwater || flying)
vec.z() = 0.0f;
if (inwater || flying)
cls.getCreatureStats(mPtr).land();
bool inJump = true;
if(!onground && !flying && !inwater)
{
// In the air (either getting up —ascending part of jump— or falling).
if (world->isSlowFalling(mPtr))
{
// SlowFalling spell effect is active, do not keep previous fall height
cls.getCreatureStats(mPtr).land();
}
forcestateupdate = (mJumpState != JumpState_InAir);
jumpstate = JumpState_InAir;
@ -1763,7 +1754,7 @@ void CharacterController::update(float duration)
}
}
}
else if(mJumpState == JumpState_InAir)
else if(mJumpState == JumpState_InAir && !inwater)
{
forcestateupdate = true;
jumpstate = JumpState_Landing;
@ -1846,9 +1837,6 @@ void CharacterController::update(float duration)
movestate = mMovementState;
}
if (onground)
cls.getCreatureStats(mPtr).land();
if(movestate != CharState_None && movestate != CharState_TurnLeft && movestate != CharState_TurnRight)
clearAnimQueue();

@ -1404,14 +1404,16 @@ namespace MWPhysics
// Slow fall reduces fall speed by a factor of (effect magnitude / 200)
float slowFall = 1.f - std::max(0.f, std::min(1.f, effects.get(ESM::MagicEffect::SlowFall).getMagnitude() * 0.005f));
bool flying = world->isFlying(iter->first);
bool wasOnGround = physicActor->getOnGround();
osg::Vec3f position = physicActor->getPosition();
float oldHeight = position.z();
bool positionChanged = false;
for (int i=0; i<numSteps; ++i)
{
position = MovementSolver::move(position, physicActor->getPtr(), physicActor, iter->second, physicsDt,
world->isFlying(iter->first),
waterlevel, slowFall, mCollisionWorld, mStandingCollisions);
flying, waterlevel, slowFall, mCollisionWorld, mStandingCollisions);
if (position != physicActor->getPosition())
positionChanged = true;
physicActor->setPosition(position); // always set even if unchanged to make sure interpolation is correct
@ -1424,8 +1426,11 @@ namespace MWPhysics
float heightDiff = position.z() - oldHeight;
if (heightDiff < 0)
iter->first.getClass().getCreatureStats(iter->first).addToFallHeight(-heightDiff);
MWMechanics::CreatureStats& stats = iter->first.getClass().getCreatureStats(iter->first);
if ((wasOnGround && physicActor->getOnGround()) || flying || world->isSwimming(iter->first) || slowFall < 1)
stats.land();
else if (heightDiff < 0)
stats.addToFallHeight(-heightDiff);
mMovementResults.push_back(std::make_pair(iter->first, interpolated));
}

Loading…
Cancel
Save