1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-03-30 15:36:45 +00:00

Set the character as being on the ground when colliding with a shallow enough slope

This commit is contained in:
Chris Robinson 2013-02-20 05:24:38 -08:00
parent fe6fa9ebe7
commit b14def7c09

View file

@ -137,45 +137,43 @@ namespace MWWorld
clipVelocity(clippedVelocity, trace.planenormal, 1.0f); clipVelocity(clippedVelocity, trace.planenormal, 1.0f);
} }
Ogre::Vector3 lastNormal(0.0f); const Ogre::Vector3 up(0.0f, 0.0f, 1.0f);
Ogre::Vector3 currentNormal(0.0f);
Ogre::Vector3 up(0.0f, 0.0f, 1.0f);
Ogre::Vector3 newPosition = position; Ogre::Vector3 newPosition = position;
int iterations = 0; int iterations = 0;
do { do {
// trace to where character would go if there were no obstructions // trace to where character would go if there were no obstructions
newtrace(&trace, newPosition, newPosition+clippedVelocity*remainingTime, halfExtents, isInterior, engine); newtrace(&trace, newPosition, newPosition+clippedVelocity*remainingTime, halfExtents, isInterior, engine);
newPosition = trace.endpos; newPosition = trace.endpos;
currentNormal = trace.planenormal;
remainingTime = remainingTime * (1.0f-trace.fraction); remainingTime = remainingTime * (1.0f-trace.fraction);
// check for obstructions // check for obstructions
if(trace.fraction < 1.0f) if(trace.fraction < 1.0f)
{ {
//std::cout<<"angle: "<<getSlope(trace.planenormal)<<"\n"; //std::cout<<"angle: "<<getSlope(trace.planenormal)<<"\n";
if(getSlope(currentNormal) > sMaxSlope || currentNormal == lastNormal) if(getSlope(trace.planenormal) <= sMaxSlope)
{ {
// We hit a slope we can walk on. Update velocity accordingly.
clipVelocity(clippedVelocity, trace.planenormal, 1.0f);
// We're only on the ground if gravity is affecting us
onground = gravity;
}
else
{
// Can't walk on this. Try to step up onto it.
if((gravity && !onground) || if((gravity && !onground) ||
!stepMove(newPosition, velocity, remainingTime, halfExtents, isInterior, engine)) !stepMove(newPosition, velocity, remainingTime, halfExtents, isInterior, engine))
{ {
Ogre::Vector3 resultantDirection = currentNormal.crossProduct(up); Ogre::Vector3 resultantDirection = trace.planenormal.crossProduct(up);
resultantDirection.normalise(); resultantDirection.normalise();
clippedVelocity = velocity; clippedVelocity = velocity;
projectVelocity(clippedVelocity, resultantDirection); projectVelocity(clippedVelocity, resultantDirection);
// just this isn't enough sometimes. It's the same problem that causes steps to be necessary on even uphill terrain. // just this isn't enough sometimes. It's the same problem that causes steps to be necessary on even uphill terrain.
clippedVelocity += currentNormal*clippedVelocity.length()/50.0f; clippedVelocity += trace.planenormal*clippedVelocity.length()/50.0f;
//std::cout<< "clipped velocity: "<<clippedVelocity <<std::endl;
} }
//else
// std::cout<< "stepped" <<std::endl;
} }
else
clipVelocity(clippedVelocity, currentNormal, 1.0f);
} }
lastNormal = currentNormal;
iterations++; iterations++;
} while(iterations < sMaxIterations && remainingTime > 0.0f); } while(iterations < sMaxIterations && remainingTime > 0.0f);