diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-09-03 12:51:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-03 12:51:42 +0200 |
commit | 720065c7214366313717f49183b9bb941a942fc5 (patch) | |
tree | 0ea878386b84dfc8018374ed0f429d46f598c1f5 | |
parent | ad9f39108f1ab35bbb661e2cd998d1dfd1db57a1 (diff) | |
parent | c12ce2b4ddaf22cb06b69a8d0c685b54485e8c05 (diff) |
Merge pull request #31476 from SoulForMachine/fix-move-and-slide-error
Prevent move_and_slide() to generate an error.
-rw-r--r-- | scene/2d/physics_body_2d.cpp | 8 | ||||
-rw-r--r-- | scene/3d/physics_body.cpp | 12 | ||||
-rw-r--r-- | scene/3d/physics_body.h | 1 |
3 files changed, 21 insertions, 0 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 7cc937a64a..9b6020e0fd 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -1446,6 +1446,14 @@ void KinematicBody2D::_direct_state_changed(Object *p_state) { void KinematicBody2D::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { last_valid_transform = get_global_transform(); + + // Reset move_and_slide() data. + on_floor = false; + on_floor_body = RID(); + on_ceiling = false; + on_wall = false; + colliders.clear(); + floor_velocity = Vector2(); } if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) { diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index ebac968cb4..0756be5fc8 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -1387,6 +1387,18 @@ Ref<KinematicCollision> KinematicBody::_get_slide_collision(int p_bounce) { return slide_colliders[p_bounce]; } +void KinematicBody::_notification(int p_what) { + if (p_what == NOTIFICATION_ENTER_TREE) { + // Reset move_and_slide() data. + on_floor = false; + on_floor_body = RID(); + on_ceiling = false; + on_wall = false; + colliders.clear(); + floor_velocity = Vector3(); + } +} + void KinematicBody::_bind_methods() { ClassDB::bind_method(D_METHOD("move_and_collide", "rel_vec", "infinite_inertia", "exclude_raycast_shapes", "test_only"), &KinematicBody::_move, DEFVAL(true), DEFVAL(true), DEFVAL(false)); diff --git a/scene/3d/physics_body.h b/scene/3d/physics_body.h index 0e2e614717..0967cb9cd5 100644 --- a/scene/3d/physics_body.h +++ b/scene/3d/physics_body.h @@ -315,6 +315,7 @@ private: Ref<KinematicCollision> _get_slide_collision(int p_bounce); protected: + void _notification(int p_what); static void _bind_methods(); public: |