From b14def7c0951fc17eff0394be34304dcf6223ad2 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Wed, 20 Feb 2013 05:24:38 -0800 Subject: [PATCH] Set the character as being on the ground when colliding with a shallow enough slope --- apps/openmw/mwworld/physicssystem.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 0b9e13fb7a..a61eebe2fc 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -137,45 +137,43 @@ namespace MWWorld clipVelocity(clippedVelocity, trace.planenormal, 1.0f); } - Ogre::Vector3 lastNormal(0.0f); - Ogre::Vector3 currentNormal(0.0f); - Ogre::Vector3 up(0.0f, 0.0f, 1.0f); + const Ogre::Vector3 up(0.0f, 0.0f, 1.0f); Ogre::Vector3 newPosition = position; int iterations = 0; do { // trace to where character would go if there were no obstructions newtrace(&trace, newPosition, newPosition+clippedVelocity*remainingTime, halfExtents, isInterior, engine); newPosition = trace.endpos; - currentNormal = trace.planenormal; remainingTime = remainingTime * (1.0f-trace.fraction); // check for obstructions if(trace.fraction < 1.0f) { //std::cout<<"angle: "< 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) || !stepMove(newPosition, velocity, remainingTime, halfExtents, isInterior, engine)) { - Ogre::Vector3 resultantDirection = currentNormal.crossProduct(up); + Ogre::Vector3 resultantDirection = trace.planenormal.crossProduct(up); resultantDirection.normalise(); clippedVelocity = velocity; projectVelocity(clippedVelocity, resultantDirection); // 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; - //std::cout<< "clipped velocity: "< 0.0f);