summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
authorPouleyKetchoupp <pouleyketchoup@gmail.com>2021-09-29 18:25:00 -0700
committerPouleyKetchoupp <pouleyketchoup@gmail.com>2021-09-29 18:30:57 -0700
commit6e6f292f154945654fcd752d5f9ee643d878cc59 (patch)
tree5eb901fa84d50f9d99bac9b5b3eeed658c26d1d7 /scene/2d
parentf72419d1525f2e5fe08f81a8fe06af3831c71c3e (diff)
Fix AnimatableBody moving and colliding during the first frame
_update_kinematic_motion() shouldn't be called in the constructor It's too early and causes a first call to set the body position to 0. Then the second call to set the actual position triggers kinematic motion, colliding with objects on the path to the initial position. Side effect of sync to physics now enabled by default.
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/physics_body_2d.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index 3281afd819..55caffad1c 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -288,6 +288,12 @@ void AnimatableBody2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
last_valid_transform = get_global_transform();
+ _update_kinematic_motion();
+ } break;
+
+ case NOTIFICATION_EXIT_TREE: {
+ set_only_update_transform_changes(false);
+ set_notify_local_transform(false);
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
@@ -313,7 +319,6 @@ void AnimatableBody2D::_bind_methods() {
AnimatableBody2D::AnimatableBody2D() :
StaticBody2D(PhysicsServer2D::BODY_MODE_KINEMATIC) {
- _update_kinematic_motion();
}
void RigidDynamicBody2D::_body_enter_tree(ObjectID p_id) {