diff options
author | fabriceci <fabricecipolla@gmail.com> | 2023-02-21 22:34:44 +0100 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-03-30 19:10:45 +0200 |
commit | bafc6372b2fee1d633f1ab85a34dc41cb8af3b27 (patch) | |
tree | e105cb6df785fe9559179e16352fb2a67661dfae /scene/2d | |
parent | 19501f8eb19481b029f67ecf78e711d42f2fc431 (diff) |
Exposes the apply_floor_snap function to allow a snap to be made regardless of velocity.
(cherry picked from commit 1381e6da4f695323853b24cf8d3632604b629133)
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/physics_body_2d.cpp | 17 | ||||
-rw-r--r-- | scene/2d/physics_body_2d.h | 2 |
2 files changed, 17 insertions, 2 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 1721bcde3b..ba361c2656 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -1391,9 +1391,13 @@ void CharacterBody2D::_move_and_slide_floating(double p_delta) { first_slide = false; } } +void CharacterBody2D::apply_floor_snap() { + _apply_floor_snap(); +} -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) { +// Method that avoids the p_wall_as_floor parameter for the public method. +void CharacterBody2D::_apply_floor_snap(bool p_wall_as_floor) { + if (on_floor) { return; } @@ -1428,6 +1432,14 @@ void CharacterBody2D::_snap_on_floor(bool p_was_on_floor, bool p_vel_dir_facing_ } } +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; + } + + _apply_floor_snap(p_wall_as_floor); +} + 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; @@ -1699,6 +1711,7 @@ void CharacterBody2D::_notification(int p_what) { void CharacterBody2D::_bind_methods() { ClassDB::bind_method(D_METHOD("move_and_slide"), &CharacterBody2D::move_and_slide); + ClassDB::bind_method(D_METHOD("apply_floor_snap"), &CharacterBody2D::apply_floor_snap); ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &CharacterBody2D::set_velocity); ClassDB::bind_method(D_METHOD("get_velocity"), &CharacterBody2D::get_velocity); diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h index 53bc5b7cd3..c4eb77d861 100644 --- a/scene/2d/physics_body_2d.h +++ b/scene/2d/physics_body_2d.h @@ -337,6 +337,7 @@ public: PLATFORM_ON_LEAVE_DO_NOTHING, }; bool move_and_slide(); + void apply_floor_snap(); const Vector2 &get_velocity() const; void set_velocity(const Vector2 &p_velocity); @@ -446,6 +447,7 @@ private: 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 _apply_floor_snap(bool p_wall_as_floor = false); void _snap_on_floor(bool p_was_on_floor, bool p_vel_dir_facing_up, bool p_wall_as_floor = false); protected: |