diff options
author | Mitchell Stokes <mogurijin@gmail.com> | 2013-01-30 09:55:17 +0400 |
---|---|---|
committer | Mitchell Stokes <mogurijin@gmail.com> | 2013-01-30 09:55:17 +0400 |
commit | 9191b783bb2bc1a2d4be2b2cd215735e68353a56 (patch) | |
tree | 8440c8b155a69580b358ded134bad49e27bb8eba /source/gameengine/Physics/Bullet/CcdPhysicsController.cpp | |
parent | 26ee2a1f79c3513ca9eaeb6a3a8d855c37088468 (diff) |
BGE: Some various changes to make moving the character physics type easier:
* Undoing the previous applyMovement() changes for characters. This was causing bugs for the Motion Actuator.
* Creating a Character Motion type for the Motion Actuator with specific controls for characters. This includes moving, rotating and jumping.
* Adding a KX_CharacterWrapper.walkDirection to set the character's direction and speed.
Note, this also resolves the following bugs:
[#33585] "Setting dLoc of motion actuator [0,0,0] via python won't stop object" reported by Manuel Bellersen (urfoex)
[#33503] "Character physics type won´t accept more than one motion anymore" reported by Mr Larodos
Diffstat (limited to 'source/gameengine/Physics/Bullet/CcdPhysicsController.cpp')
-rw-r--r-- | source/gameengine/Physics/Bullet/CcdPhysicsController.cpp | 57 |
1 files changed, 47 insertions, 10 deletions
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp index cf96f22a345..0bf11fd2f9d 100644 --- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp +++ b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp @@ -115,6 +115,11 @@ void BlenderBulletCharacterController::jump() m_jumps++; } +const btVector3& BlenderBulletCharacterController::getWalkDirection() +{ + return m_walkDirection; +} + CcdPhysicsController::CcdPhysicsController (const CcdConstructionInfo& ci) :m_cci(ci) { @@ -926,20 +931,27 @@ void CcdPhysicsController::RelativeTranslate(float dlocX,float dlocY,float dloc if (local) dloc = xform.getBasis()*dloc; - if (m_characterController) - { - m_characterController->setWalkDirection(dloc/GetPhysicsEnvironment()->getNumTimeSubSteps()); - } - else - { - - xform.setOrigin(xform.getOrigin() + dloc); - SetCenterOfMassTransform(xform); - } + xform.setOrigin(xform.getOrigin() + dloc); + SetCenterOfMassTransform(xform); } } +void CcdPhysicsController::SetWalkDirection(float dirX,float dirY,float dirZ,bool local) +{ + + if (m_object && m_characterController) + { + btVector3 dir(dirX,dirY,dirZ); + btTransform xform = m_object->getWorldTransform(); + + if (local) + dir = xform.getBasis()*dir; + + m_characterController->setWalkDirection(dir/GetPhysicsEnvironment()->getNumTimeSubSteps()); + } +} + void CcdPhysicsController::RelativeRotate(const float rotval[9],bool local) { if (m_object) @@ -1267,6 +1279,13 @@ void CcdPhysicsController::applyImpulse(float attachX,float attachY,float attac } } + +void CcdPhysicsController::Jump() +{ + if (m_object && m_characterController) + m_characterController->jump(); +} + void CcdPhysicsController::SetActive(bool active) { } @@ -1323,6 +1342,24 @@ void CcdPhysicsController::GetVelocity(const float posX,const float posY,const linvZ = 0.f; } } + +void CcdPhysicsController::GetWalkDirection(float& dirX,float& dirY,float& dirZ) +{ + if (m_object && m_characterController) + { + const btVector3 dir = m_characterController->getWalkDirection(); + dirX = dir.x(); + dirY = dir.y(); + dirZ = dir.z(); + } + else + { + dirX = 0.f; + dirY = 0.f; + dirZ = 0.f; + } +} + void CcdPhysicsController::getReactionForce(float& forceX,float& forceY,float& forceZ) { } |