Merge pull request #59297 from fabriceci/fix-jitter-2D-slight-slope

This commit is contained in:
Rémi Verschelde 2022-04-29 15:33:45 +02:00 committed by GitHub
commit a817bd96c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 14 deletions

View File

@ -1257,7 +1257,7 @@ void CharacterBody2D::_move_and_slide_grounded(double p_delta, bool p_was_on_flo
set_global_transform(gt);
}
// Determines if you are on the ground.
_snap_on_floor(true, false);
_snap_on_floor(true, false, true);
velocity = Vector2();
last_motion = Vector2();
motion = Vector2();
@ -1396,8 +1396,8 @@ void CharacterBody2D::_move_and_slide_floating(double p_delta) {
}
}
void CharacterBody2D::_snap_on_floor(bool was_on_floor, bool vel_dir_facing_up) {
if (on_floor || !was_on_floor || vel_dir_facing_up) {
void CharacterBody2D::_snap_on_floor(bool p_was_on_floor, bool p_vel_dir_facing_up, bool p_wall_as_floor) {
if (on_floor || !p_was_on_floor || p_vel_dir_facing_up) {
return;
}
@ -1409,7 +1409,8 @@ void CharacterBody2D::_snap_on_floor(bool was_on_floor, bool vel_dir_facing_up)
PhysicsServer2D::MotionResult result;
if (move_and_collide(parameters, result, true, false)) {
if (result.get_angle(up_direction) <= floor_max_angle + FLOOR_ANGLE_THRESHOLD) {
if ((result.get_angle(up_direction) <= floor_max_angle + FLOOR_ANGLE_THRESHOLD) ||
(p_wall_as_floor && result.get_angle(-up_direction) > floor_max_angle + FLOOR_ANGLE_THRESHOLD)) {
on_floor = true;
floor_normal = result.collision_normal;
_set_platform_data(result);
@ -1430,8 +1431,8 @@ void CharacterBody2D::_snap_on_floor(bool was_on_floor, bool vel_dir_facing_up)
}
}
bool CharacterBody2D::_on_floor_if_snapped(bool was_on_floor, bool vel_dir_facing_up) {
if (up_direction == Vector2() || on_floor || !was_on_floor || vel_dir_facing_up) {
bool CharacterBody2D::_on_floor_if_snapped(bool p_was_on_floor, bool p_vel_dir_facing_up) {
if (up_direction == Vector2() || on_floor || !p_was_on_floor || p_vel_dir_facing_up) {
return false;
}

View File

@ -441,11 +441,11 @@ private:
Ref<KinematicCollision2D> _get_slide_collision(int p_bounce);
Ref<KinematicCollision2D> _get_last_slide_collision();
const Vector2 &get_up_direction() const;
bool _on_floor_if_snapped(bool was_on_floor, bool vel_dir_facing_up);
bool _on_floor_if_snapped(bool p_was_on_floor, bool p_vel_dir_facing_up);
void set_up_direction(const Vector2 &p_up_direction);
void _set_collision_direction(const PhysicsServer2D::MotionResult &p_result);
void _set_platform_data(const PhysicsServer2D::MotionResult &p_result);
void _snap_on_floor(bool was_on_floor, bool vel_dir_facing_up);
void _snap_on_floor(bool p_was_on_floor, bool p_vel_dir_facing_up, bool p_wall_as_floor = false);
protected:
void _notification(int p_what);

View File

@ -1565,8 +1565,8 @@ void CharacterBody3D::_move_and_slide_floating(double p_delta) {
}
}
void CharacterBody3D::_snap_on_floor(bool was_on_floor, bool vel_dir_facing_up) {
if (collision_state.floor || !was_on_floor || vel_dir_facing_up) {
void CharacterBody3D::_snap_on_floor(bool p_was_on_floor, bool p_vel_dir_facing_up) {
if (collision_state.floor || !p_was_on_floor || p_vel_dir_facing_up) {
return;
}
@ -1600,8 +1600,8 @@ void CharacterBody3D::_snap_on_floor(bool was_on_floor, bool vel_dir_facing_up)
}
}
bool CharacterBody3D::_on_floor_if_snapped(bool was_on_floor, bool vel_dir_facing_up) {
if (up_direction == Vector3() || collision_state.floor || !was_on_floor || vel_dir_facing_up) {
bool CharacterBody3D::_on_floor_if_snapped(bool p_was_on_floor, bool p_vel_dir_facing_up) {
if (up_direction == Vector3() || collision_state.floor || !p_was_on_floor || p_vel_dir_facing_up) {
return false;
}

View File

@ -474,11 +474,11 @@ private:
Ref<KinematicCollision3D> _get_slide_collision(int p_bounce);
Ref<KinematicCollision3D> _get_last_slide_collision();
const Vector3 &get_up_direction() const;
bool _on_floor_if_snapped(bool was_on_floor, bool vel_dir_facing_up);
bool _on_floor_if_snapped(bool p_was_on_floor, bool p_vel_dir_facing_up);
void set_up_direction(const Vector3 &p_up_direction);
void _set_collision_direction(const PhysicsServer3D::MotionResult &p_result, CollisionState &r_state, CollisionState p_apply_state = CollisionState(true, true, true));
void _set_platform_data(const PhysicsServer3D::MotionCollision &p_collision);
void _snap_on_floor(bool was_on_floor, bool vel_dir_facing_up);
void _snap_on_floor(bool p_was_on_floor, bool p_vel_dir_facing_up);
protected:
void _notification(int p_what);