Skip to content

Commit

Permalink
Turn on recovery as collisions only for floor snapping as this leads …
Browse files Browse the repository at this point in the history
…to unwanted behaviour for other surface than the floor.
  • Loading branch information
fabriceci committed Sep 18, 2022
1 parent e5594c2 commit 10395f5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
7 changes: 2 additions & 5 deletions scene/2d/physics_body_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,6 @@ bool CharacterBody2D::move_and_slide() {

if (!current_platform_velocity.is_zero_approx()) {
PhysicsServer2D::MotionParameters parameters(get_global_transform(), current_platform_velocity * delta, margin);
parameters.recovery_as_collision = true; // Also report collisions generated only from recovery.
parameters.exclude_bodies.insert(platform_rid);
if (platform_object_id.is_valid()) {
parameters.exclude_objects.insert(platform_object_id);
Expand Down Expand Up @@ -1203,7 +1202,6 @@ void CharacterBody2D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo

for (int iteration = 0; iteration < max_slides; ++iteration) {
PhysicsServer2D::MotionParameters parameters(get_global_transform(), motion, margin);
parameters.recovery_as_collision = true; // Also report collisions generated only from recovery.

Vector2 prev_position = parameters.from.columns[2];

Expand Down Expand Up @@ -1360,7 +1358,6 @@ void CharacterBody2D::_move_and_slide_floating(double p_delta) {
bool first_slide = true;
for (int iteration = 0; iteration < max_slides; ++iteration) {
PhysicsServer2D::MotionParameters parameters(get_global_transform(), motion, margin);
parameters.recovery_as_collision = true; // Also report collisions generated only from recovery.

PhysicsServer2D::MotionResult result;
bool collided = move_and_collide(parameters, result, false, false);
Expand Down Expand Up @@ -1407,7 +1404,7 @@ void CharacterBody2D::_snap_on_floor(bool p_was_on_floor, bool p_vel_dir_facing_
real_t length = MAX(floor_snap_length, margin);

PhysicsServer2D::MotionParameters parameters(get_global_transform(), -up_direction * length, margin);
parameters.recovery_as_collision = true; // Also report collisions generated only from recovery.
parameters.recovery_as_collision = true; // Report margin recovery as collision to improve floor detection.
parameters.collide_separation_ray = true;

PhysicsServer2D::MotionResult result;
Expand Down Expand Up @@ -1443,7 +1440,7 @@ bool CharacterBody2D::_on_floor_if_snapped(bool p_was_on_floor, bool p_vel_dir_f
real_t length = MAX(floor_snap_length, margin);

PhysicsServer2D::MotionParameters parameters(get_global_transform(), -up_direction * length, margin);
parameters.recovery_as_collision = true; // Also report collisions generated only from recovery.
parameters.recovery_as_collision = true; // Report margin recovery as collision to improve floor detection.
parameters.collide_separation_ray = true;

PhysicsServer2D::MotionResult result;
Expand Down
7 changes: 2 additions & 5 deletions scene/3d/physics_body_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,6 @@ bool CharacterBody3D::move_and_slide() {

if (!current_platform_velocity.is_zero_approx()) {
PhysicsServer3D::MotionParameters parameters(get_global_transform(), current_platform_velocity * delta, margin);
parameters.recovery_as_collision = true; // Also report collisions generated only from recovery.

parameters.exclude_bodies.insert(platform_rid);
if (platform_object_id.is_valid()) {
Expand Down Expand Up @@ -1275,7 +1274,6 @@ void CharacterBody3D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
for (int iteration = 0; iteration < max_slides; ++iteration) {
PhysicsServer3D::MotionParameters parameters(get_global_transform(), motion, margin);
parameters.max_collisions = 4;
parameters.recovery_as_collision = true; // Also report collisions generated only from recovery.

PhysicsServer3D::MotionResult result;
bool collided = move_and_collide(parameters, result, false, !sliding_enabled);
Expand Down Expand Up @@ -1520,7 +1518,6 @@ void CharacterBody3D::_move_and_slide_floating(double p_delta) {
bool first_slide = true;
for (int iteration = 0; iteration < max_slides; ++iteration) {
PhysicsServer3D::MotionParameters parameters(get_global_transform(), motion, margin);
parameters.recovery_as_collision = true; // Also report collisions generated only from recovery.

PhysicsServer3D::MotionResult result;
bool collided = move_and_collide(parameters, result, false, false);
Expand Down Expand Up @@ -1575,7 +1572,7 @@ void CharacterBody3D::_snap_on_floor(bool p_was_on_floor, bool p_vel_dir_facing_

PhysicsServer3D::MotionParameters parameters(get_global_transform(), -up_direction * length, margin);
parameters.max_collisions = 4;
parameters.recovery_as_collision = true; // Also report collisions generated only from recovery.
parameters.recovery_as_collision = true; // Report margin recovery as collision to improve floor detection.
parameters.collide_separation_ray = true;

PhysicsServer3D::MotionResult result;
Expand Down Expand Up @@ -1611,7 +1608,7 @@ bool CharacterBody3D::_on_floor_if_snapped(bool p_was_on_floor, bool p_vel_dir_f

PhysicsServer3D::MotionParameters parameters(get_global_transform(), -up_direction * length, margin);
parameters.max_collisions = 4;
parameters.recovery_as_collision = true; // Also report collisions generated only from recovery.
parameters.recovery_as_collision = true; // Report margin recovery as collision to improve floor detection.
parameters.collide_separation_ray = true;

PhysicsServer3D::MotionResult result;
Expand Down
2 changes: 1 addition & 1 deletion servers/physics_server_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ class PhysicsServer2D : public Object {
bool collide_separation_ray = false;
HashSet<RID> exclude_bodies;
HashSet<ObjectID> exclude_objects;
bool recovery_as_collision = false;
bool recovery_as_collision = false; // Don't report margin recovery as collision by default, only used for floor snapping.

MotionParameters() {}

Expand Down
2 changes: 1 addition & 1 deletion servers/physics_server_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ class PhysicsServer3D : public Object {
bool collide_separation_ray = false;
HashSet<RID> exclude_bodies;
HashSet<ObjectID> exclude_objects;
bool recovery_as_collision = false;
bool recovery_as_collision = false; // Don't report margin recovery as collision by default, only used for floor snapping.

MotionParameters() {}

Expand Down

0 comments on commit 10395f5

Please sign in to comment.