Showing the changes to libraries/physics/src/CharacterController.cpp (1 of 1 file). Show all
Unified · Split
| @@ -786,14 +786,17 @@ void CharacterController::setEnabled(bool enabled) { · 785 unmodified lines | |||
| 786 | 786 | ||
| 787 | void CharacterController::setDynamicsWorld(btDynamicsWorld* world) { | 787 | void CharacterController::setDynamicsWorld(btDynamicsWorld* world) { |
| 788 | if (_dynamicsWorld != world) { | 788 | if (_dynamicsWorld != world) { |
| 789 | if (_dynamicsWorld) { | 789 | if (_dynamicsWorld) { |
| 790 | _dynamicsWorld->removeCollisionObject(getGhostObject()); | 790 | if (_ghostObject) { |
| 791 | _dynamicsWorld->removeAction(this); | 791 | _dynamicsWorld->removeCollisionObject(_ghostObject); |
| 792 | _dynamicsWorld->removeAction(this); | ||
| 793 | } | ||
| 794 | _dynamicsWorld = NULL; | ||
| 792 | } | 795 | } |
| 793 | _dynamicsWorld = world; | 796 | if (world && _ghostObject) { |
| 794 | if (_dynamicsWorld) { | 797 | _dynamicsWorld = world; |
| 795 | _pendingFlags &= ~ PENDING_FLAG_JUMP; | 798 | _pendingFlags &= ~ PENDING_FLAG_JUMP; |
| 796 | _dynamicsWorld->addCollisionObject(getGhostObject(), | 799 | _dynamicsWorld->addCollisionObject(_ghostObject, |
| 797 | btBroadphaseProxy::CharacterFilter, | 800 | btBroadphaseProxy::CharacterFilter, |
| 798 | btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter); | 801 | btBroadphaseProxy::StaticFilter | btBroadphaseProxy::DefaultFilter); |
| 799 | _dynamicsWorld->addAction(this); | 802 | _dynamicsWorld->addAction(this); |
| @@ -876,7 +879,7 @@ void CharacterController::preSimulation(btScalar timeStep) { · 76 unmodified lines | |||
| 876 | } | 879 | } |
| 877 | 880 | ||
| 878 | void CharacterController::postSimulation() { | 881 | void CharacterController::postSimulation() { |
| 879 | if (_enabled) { | 882 | if (_enabled && _ghostObject) { |
| 880 | const btTransform& avatarTransform = _ghostObject->getWorldTransform(); | 883 | const btTransform& avatarTransform = _ghostObject->getWorldTransform(); |
| 881 | glm::quat rotation = bulletToGLM(avatarTransform.getRotation()); | 884 | glm::quat rotation = bulletToGLM(avatarTransform.getRotation()); |
| 882 | glm::vec3 position = bulletToGLM(avatarTransform.getOrigin()); | 885 | glm::vec3 position = bulletToGLM(avatarTransform.getOrigin()); |