summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamille Mohr-Daurat <pouleyKetchoup@gmail.com>2021-11-22 08:16:16 -0700
committerGitHub <noreply@github.com>2021-11-22 08:16:16 -0700
commit8daf0cc49c4bab8dd039ced214e527b21708661e (patch)
tree1684657a28e8be367708dcc960ef68aaeb53b9ab
parent29a2561f77c2004433955a8578301cf49401fdd5 (diff)
parenta86d73ef3bfa0374e7a08a49ff8267cae00808c3 (diff)
Merge pull request #55216 from fabriceci/fix-body-stuck-complex-scenario-3d
Fix CharacterBody3D stuck in some advanced scenario
-rw-r--r--scene/3d/physics_body_3d.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp
index 5cb7f431e3..b731e0a2da 100644
--- a/scene/3d/physics_body_3d.cpp
+++ b/scene/3d/physics_body_3d.cpp
@@ -1584,6 +1584,7 @@ void CharacterBody3D::_set_collision_direction(const PhysicsServer3D::MotionResu
Vector3 prev_wall_normal = wall_normal;
int wall_collision_count = 0;
Vector3 combined_wall_normal;
+ Vector3 tmp_wall_col; // Avoid duplicate on average calculation.
for (int i = p_result.collision_count - 1; i >= 0; i--) {
const PhysicsServer3D::MotionCollision &collision = p_result.collisions[i];
@@ -1630,8 +1631,11 @@ void CharacterBody3D::_set_collision_direction(const PhysicsServer3D::MotionResu
}
// Collect normal for calculating average.
- combined_wall_normal += collision.normal;
- wall_collision_count++;
+ if (!collision.normal.is_equal_approx(tmp_wall_col)) {
+ tmp_wall_col = collision.normal;
+ combined_wall_normal += collision.normal;
+ wall_collision_count++;
+ }
}
if (r_state.wall) {