Teleporting a KinematicBody2D when paused has weird interactions

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ravenblack
:warning: Old Version Published before Godot 3 was released.

I have a global “Man” object that I want to move between scenes. During the transition I do:


`get_tree().set_pause(true)
(play a pause-resistant transition animation)
(load the new scene)
Man.set_global_pos(position of entrance marker node in new scene)
(play a pause-resistant return-transition animation)
get_tree().set_pause(false)`

After this unpause, for one frame Man acts like he’s still in the pre-teleport position, triggering colliders and having unexpected ray-casts. I hacked around some of these side-effects by setting a “skip_frame_” boolean in Man_, and if that’s true in _fixed_process, set it to false and return immediately. This resolved the unwanted interactions in Man’s code, but unwanted colliders are still triggered by the outdated location. (And obviously I’d rather not have to inject this weird hack anyway.)

Is there some way to make the position of a KinematicBody2D fully update while the tree is paused?

This is with v2.1.3.stable.official

:bust_in_silhouette: Reply From: kidscancode

Two possibilities:

  • Have you tried using 2.1.4? There were some bug fixes that may address your issue.

  • Have you checked “Motion Fix Enabled” in Project Settings > Physics 2d ? It’s not enabled by default in 2.1.3 (it is the default for new projects in 2.1.4).

Motion Fix Enabled fixed the weird direct interactions in Man’s _fixed_process (the Man no longer thinks he’s touching floor for one frame after he is teleported into the air). So thanks for that pointer.

The unexpected collision zone interaction still occurs though, triggering a BodyEnter(Man) sensor at the location the Man was in before the scene transition, even if I do Man.set_global_pos(Vector2(-99999, -99999)) immediately before loading the scene containing that sensor zone.

I think maybe the best solution for me here is to not retain the Man across scene transitions, and instead re-instance a new Man with saved attributes (storing those attributes in a global) after loading a new scene. That way there can’t be any residual tainted physics attributes left over from the previous Man instance.

(This is with 2.1.4 now, that didn’t fix the surprise collision detection.)

ravenblack | 2017-09-07 02:42