1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-04 03:40:14 +00:00

Improve stepping down when starting on the ground

This commit is contained in:
Chris Robinson 2013-08-19 08:09:23 -07:00
parent 3ca4d54bf9
commit 48e594b7c4

View File

@ -128,6 +128,7 @@ namespace MWWorld
position.z += halfExtents.z; position.z += halfExtents.z;
OEngine::Physic::ActorTracer tracer; OEngine::Physic::ActorTracer tracer;
bool wasOnGround = false;
bool isOnGround = false; bool isOnGround = false;
Ogre::Vector3 inertia(0.0f); Ogre::Vector3 inertia(0.0f);
Ogre::Vector3 velocity; Ogre::Vector3 velocity;
@ -140,15 +141,22 @@ namespace MWWorld
} }
else else
{ {
velocity = Ogre::Quaternion(Ogre::Radian(-refpos.rot[2]), Ogre::Vector3::UNIT_Z) * movement;
if(physicActor->getOnGround())
inertia = velocity;
else
{
inertia = physicActor->getInertialForce();
velocity += inertia;
}
if(!(movement.z > 0.0f)) if(!(movement.z > 0.0f))
{ {
wasOnGround = physicActor->getOnGround();
tracer.doTrace(colobj, position, position-Ogre::Vector3(0,0,2), engine); tracer.doTrace(colobj, position, position-Ogre::Vector3(0,0,2), engine);
if(tracer.mFraction < 1.0f && getSlope(tracer.mPlaneNormal) <= sMaxSlope) if(tracer.mFraction < 1.0f && getSlope(tracer.mPlaneNormal) <= sMaxSlope)
isOnGround = true; isOnGround = true;
} }
inertia = physicActor->getInertialForce();
velocity = Ogre::Quaternion(Ogre::Radian(-refpos.rot[2]), Ogre::Vector3::UNIT_Z) * movement;
velocity += inertia;
} }
if(isOnGround) if(isOnGround)
@ -172,10 +180,9 @@ namespace MWWorld
break; break;
} }
//std::cout<<"angle: "<<getSlope(trace.planenormal)<<"\n";
// We hit something. Try to step up onto it. // We hit something. Try to step up onto it.
if(stepMove(colobj, newPosition, velocity, remainingTime, engine)) if(stepMove(colobj, newPosition, velocity, remainingTime, engine))
isOnGround = gravity; isOnGround = gravity; // Only on the ground if there's gravity
else else
{ {
// Can't move this way, try to find another spot along the plane // Can't move this way, try to find another spot along the plane
@ -191,21 +198,22 @@ namespace MWWorld
} }
} }
if(isOnGround) if(isOnGround || wasOnGround)
{ {
tracer.doTrace(colobj, newPosition, newPosition-Ogre::Vector3(0,0,sStepSize+2.0f), engine); tracer.doTrace(colobj, newPosition, newPosition-Ogre::Vector3(0,0,sStepSize+2.0f), engine);
if(tracer.mFraction < 1.0f && getSlope(tracer.mPlaneNormal) <= sMaxSlope) if(tracer.mFraction < 1.0f && getSlope(tracer.mPlaneNormal) <= sMaxSlope)
{
newPosition.z = tracer.mEndPos.z + 1.0f; newPosition.z = tracer.mEndPos.z + 1.0f;
isOnGround = true;
}
else else
isOnGround = false; isOnGround = false;
} }
if(isOnGround) if(isOnGround || !gravity)
physicActor->setInertialForce(Ogre::Vector3(0.0f)); physicActor->setInertialForce(Ogre::Vector3(0.0f));
else else
{ {
if(physicActor->getOnGround())
inertia = velocity;
inertia.z -= time*627.2f; inertia.z -= time*627.2f;
physicActor->setInertialForce(inertia); physicActor->setInertialForce(inertia);
} }