diff options
author | Andrea Catania <info@andreacatania.com> | 2018-09-07 20:38:30 +0200 |
---|---|---|
committer | Andrea Catania <info@andreacatania.com> | 2018-09-07 20:38:30 +0200 |
commit | 3eaaf712db9a2319873ff6d758ac20778edbd133 (patch) | |
tree | 833ef97d5cec5ab5352fdb745697c715b833b958 /modules/bullet/rigid_body_bullet.cpp | |
parent | fc50728d451e438db245d92698115cfc9c3720cf (diff) |
Fixed crash during raycast and CCD radius calculation
Diffstat (limited to 'modules/bullet/rigid_body_bullet.cpp')
-rw-r--r-- | modules/bullet/rigid_body_bullet.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/modules/bullet/rigid_body_bullet.cpp b/modules/bullet/rigid_body_bullet.cpp index 2974d6b3e4..73f0393684 100644 --- a/modules/bullet/rigid_body_bullet.cpp +++ b/modules/bullet/rigid_body_bullet.cpp @@ -316,6 +316,7 @@ void RigidBodyBullet::destroy_kinematic_utilities() { void RigidBodyBullet::main_shape_resetted() { btBody->setCollisionShape(get_main_shape()); + set_continuous_collision_detection(is_continuous_collision_detection_enabled()); // Reset } void RigidBodyBullet::reload_body() { @@ -716,15 +717,19 @@ void RigidBodyBullet::set_continuous_collision_detection(bool p_enable) { if (p_enable) { // This threshold enable CCD if the object moves more than // 1 meter in one simulation frame - btBody->setCcdMotionThreshold(1); + btBody->setCcdMotionThreshold(0.1); /// Calculate using the rule writte below the CCD swept sphere radius /// CCD works on an embedded sphere of radius, make sure this radius /// is embedded inside the convex objects, preferably smaller: /// for an object of dimensions 1 meter, try 0.2 - btVector3 center; btScalar radius; - btBody->getCollisionShape()->getBoundingSphere(center, radius); + if (btBody->getCollisionShape()) { + btVector3 center; + btBody->getCollisionShape()->getBoundingSphere(center, radius); + } else { + radius = 0; + } btBody->setCcdSweptSphereRadius(radius * 0.2); } else { btBody->setCcdMotionThreshold(0.); @@ -733,7 +738,7 @@ void RigidBodyBullet::set_continuous_collision_detection(bool p_enable) { } bool RigidBodyBullet::is_continuous_collision_detection_enabled() const { - return 0. != btBody->getCcdMotionThreshold(); + return 0. < btBody->getCcdMotionThreshold(); } void RigidBodyBullet::set_linear_velocity(const Vector3 &p_velocity) { |