summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
authorfabriceci <fabricecipolla@gmail.com>2022-03-18 20:49:56 +0100
committerfabriceci <fabricecipolla@gmail.com>2022-03-21 09:08:52 +0100
commit528dfbf63ec950929d831b5a5ce29f1c93c10360 (patch)
treedf3fb4aededc5264fb7d4a0506b6392f51d1383b /scene/2d
parent35eec4de40ed25eeb4423fcd6ae65936db9961ec (diff)
Fix 2D jitter on slight slope
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/physics_body_2d.cpp13
-rw-r--r--scene/2d/physics_body_2d.h4
2 files changed, 9 insertions, 8 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index eb4d9d6445..dc1378f14b 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -1253,7 +1253,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();
@@ -1392,8 +1392,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;
}
@@ -1405,7 +1405,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);
@@ -1426,8 +1427,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;
}
diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h
index 8d9e31d4dd..1e4483b4d0 100644
--- a/scene/2d/physics_body_2d.h
+++ b/scene/2d/physics_body_2d.h
@@ -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);