浏览代码

Merge pull request #1625 from Areloch/WalkingBullet

Fixes some bullet physics issues with the player class
Areloch 9 年之前
父节点
当前提交
7327c2a415
共有 2 个文件被更改,包括 19 次插入10 次删除
  1. 15 10
      Engine/source/T3D/physics/bullet/btPlayer.cpp
  2. 4 0
      Engine/source/T3D/physics/bullet/btPlayer.h

+ 15 - 10
Engine/source/T3D/physics/bullet/btPlayer.cpp

@@ -71,6 +71,7 @@ void BtPlayer::init( const char *type,
    mObject = obj;
    mObject = obj;
    mWorld = (BtWorld*)world;
    mWorld = (BtWorld*)world;
 
 
+   mSlopeAngle = runSurfaceCos;
    mStepHeight = stepHeight;
    mStepHeight = stepHeight;
 
 
    //if ( dStricmp( type, "Capsule" ) == 0 )
    //if ( dStricmp( type, "Capsule" ) == 0 )
@@ -102,6 +103,17 @@ Point3F BtPlayer::move( const VectorF &disp, CollisionList &outCol )
 {
 {
    AssertFatal( mGhostObject, "BtPlayer::move - The controller is null!" );
    AssertFatal( mGhostObject, "BtPlayer::move - The controller is null!" );
 
 
+   if (!mWorld->isEnabled())
+   {
+      btTransform currentTrans = mGhostObject->getWorldTransform();
+      btVector3 currentPos = currentTrans.getOrigin();
+
+      Point3F returnPos = btCast<Point3F>(currentPos);
+     
+      returnPos.z -= mOriginOffset;
+      return returnPos;
+   }
+
    // First recover from any penetrations from the previous tick.
    // First recover from any penetrations from the previous tick.
    U32 numPenetrationLoops = 0;
    U32 numPenetrationLoops = 0;
    bool touchingContact = false;
    bool touchingContact = false;
@@ -305,16 +317,9 @@ bool BtPlayer::_sweep( btVector3 *inOutCurrPos, const btVector3 &disp, Collision
          col.normal = btCast<Point3F>( callback.m_hitNormalWorld );
          col.normal = btCast<Point3F>( callback.m_hitNormalWorld );
          col.object = PhysicsUserData::getObject( callback.m_hitCollisionObject->getUserPointer() );
          col.object = PhysicsUserData::getObject( callback.m_hitCollisionObject->getUserPointer() );
 
 
-         if (disp.z() < 0.0f)
-         {
-            // We're sweeping down as part of the stepping routine.    In this
-            // case we want to have the collision normal only point in the opposite direction.
-            // i.e. up  If we include the sideways part of the normal then the Player class
-            // velocity calculations using this normal will affect the player's forwards
-            // momentum.  This is especially noticable on stairs as the rounded bottom of
-            // the capsule slides up the corner of a stair.
-            col.normal.set(0.0f, 0.0f, 1.0f);
-         }
+         F32 vd = col.normal.z;
+         if (vd < mSlopeAngle)
+            return false;
       }
       }
 
 
       return true;
       return true;

+ 4 - 0
Engine/source/T3D/physics/bullet/btPlayer.h

@@ -57,6 +57,10 @@ protected:
    ///
    ///
    F32 mOriginOffset;
    F32 mOriginOffset;
 
 
+   ///
+   F32 mSlopeAngle;
+   ///
+
    ///
    ///
    F32 mStepHeight;
    F32 mStepHeight;
    ///
    ///