Skip to content

Commit

Permalink
Hack as a hot fix for Bullet's collision margin issue
Browse files Browse the repository at this point in the history
(cherry picked from commit b3210c5)
  • Loading branch information
fabriceci authored and akien-mga committed Aug 30, 2022
1 parent 5296ab8 commit 6029200
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion scene/3d/physics_body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,8 +962,13 @@ Ref<KinematicCollision> KinematicBody::_move(const Vector3 &p_motion, bool p_inf

bool collided = move_and_collide(p_motion, p_infinite_inertia, col, p_exclude_raycast_shapes, p_test_only);

// Ugly hack as a hot fix, 65b3200 fix an issue but cause a problem with Bullet that broke games using Bullet.
// The bug is something internal to Bullet, seems to be related to the Bullet’s margin. As not proper fix was found yet,
// this temporary solution solves the issue for games using Bullet.
bool is_bullet = PhysicsServerManager::current_server_id != 0;

// Don't report collision when the whole motion is done.
if (collided && col.collision_safe_fraction < 1) {
if (collided && (col.collision_safe_fraction < 1 || is_bullet)) {
// Create a new instance when the cached reference is invalid or still in use in script.
if (motion_cache.is_null() || motion_cache->reference_get_count() > 1) {
motion_cache.instance();
Expand Down
3 changes: 3 additions & 0 deletions servers/physics_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,7 @@ PhysicsServer::~PhysicsServer() {

Vector<PhysicsServerManager::ClassInfo> PhysicsServerManager::physics_servers;
int PhysicsServerManager::default_server_id = -1;
int PhysicsServerManager::current_server_id = -1;
int PhysicsServerManager::default_server_priority = -1;
const String PhysicsServerManager::setting_property_name(PNAME("physics/3d/physics_engine"));

Expand Down Expand Up @@ -857,6 +858,7 @@ String PhysicsServerManager::get_server_name(int p_id) {

PhysicsServer *PhysicsServerManager::new_default_server() {
ERR_FAIL_COND_V(default_server_id == -1, nullptr);
current_server_id = default_server_id;
return physics_servers[default_server_id].create_callback();
}

Expand All @@ -865,6 +867,7 @@ PhysicsServer *PhysicsServerManager::new_server(const String &p_name) {
if (id == -1) {
return nullptr;
} else {
current_server_id = id;
return physics_servers[id].create_callback();
}
}
1 change: 1 addition & 0 deletions servers/physics_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ class PhysicsServerManager {

public:
static const String setting_property_name;
static int current_server_id;

private:
static void on_servers_changed();
Expand Down

0 comments on commit 6029200

Please sign in to comment.