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/3d | |
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/3d')
-rw-r--r-- | scene/3d/physics_body_3d.cpp | 13 | ||||
-rw-r--r-- | scene/3d/physics_body_3d.h | 1 |
2 files changed, 12 insertions, 2 deletions
diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp index c8cfcf7d7a..ab5b054bb3 100644 --- a/scene/3d/physics_body_3d.cpp +++ b/scene/3d/physics_body_3d.cpp @@ -1565,8 +1565,8 @@ void CharacterBody3D::_move_and_slide_floating(double p_delta) { } } -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) { +void CharacterBody3D::apply_floor_snap() { + if (collision_state.floor) { return; } @@ -1601,6 +1601,14 @@ void CharacterBody3D::_snap_on_floor(bool p_was_on_floor, bool p_vel_dir_facing_ } } +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; + } + + apply_floor_snap(); +} + 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; @@ -1954,6 +1962,7 @@ void CharacterBody3D::_notification(int p_what) { void CharacterBody3D::_bind_methods() { ClassDB::bind_method(D_METHOD("move_and_slide"), &CharacterBody3D::move_and_slide); + ClassDB::bind_method(D_METHOD("apply_floor_snap"), &CharacterBody3D::apply_floor_snap); ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &CharacterBody3D::set_velocity); ClassDB::bind_method(D_METHOD("get_velocity"), &CharacterBody3D::get_velocity); diff --git a/scene/3d/physics_body_3d.h b/scene/3d/physics_body_3d.h index 92d4726bb5..d141c1aaa2 100644 --- a/scene/3d/physics_body_3d.h +++ b/scene/3d/physics_body_3d.h @@ -354,6 +354,7 @@ public: PLATFORM_ON_LEAVE_DO_NOTHING, }; bool move_and_slide(); + void apply_floor_snap(); const Vector3 &get_velocity() const; void set_velocity(const Vector3 &p_velocity); |