Teleporting a KinematicBody2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jtumain

Hi everyone,

Short Version
How do you set the position of a KinematicBody2D without effecting its velocity?

Long Version
I’m making a 2D game that has gravitational elements, so occasionally the player maybe upside down. I have set up portals that the user can teleport between using NodePaths, assigning the target node on a portal to another portal and getting the target node’s position to set the players position using:
global_position = get_node(teleport_target).position

The player moves to the correct position, however if the player goes in the portal upside down in the air (i.e. is going upwards as if they’re being pulled to the ceiling); when they come out the other, the velocity does not stay the same and they get pulled downwards as if gravity has returned to normal.

One thing to note, is that after teleporting the move_and_slide call in my physics_process, is_on_wall() is “true” for some reason.

Is there something that I’m missing or need to know to fix this issue.

Thanks for any help in advance.

:bust_in_silhouette: Reply From: jtumain

Sorry, the issue was my own misunderstanding.

I use a visibilityNotifier2d to detect when the player is out of the camera bounds to kill them. This was happening when the player teleported, meaning the game was reset, so everything is working as intended.