How to teleport a KinematicBody to a certain position

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

I am currently working on a 3d jump and run game. When the player enters an area he should respawn. I did this by restarting the scene but the music restarted, too. I want the music to play constantly in the background, even after the player dies. Instead of restarting the scene, I tried to teleport the player back to the beginning of the level, but i could find nothing about teleporting players in 3d in the internet.

How can I teleport a KinematicBody in 3d space?

:bust_in_silhouette: Reply From: Sween123

No need to restart the scene, that is similar to using get_tree().reload_current_scene() which will literally really restart the whole thing, you can “restart” the scene by using your own methods.
To teleport a player to a target position, you can simply change the node’s “position” property.
If you have different levels that are different scenes, which means that just changing the position won’t work, you need to have methods like level_start(level), level_finished(level), go_to_level(level), or something like that to keep things organized.
When player dies, if you want it to go back to the beginning of the level, use method level_start(), or whatever your method’s name is.
If you want to go to a different level, call go_to_level().
So, if you didn’t create some methods or similar methods, go and add them. When the game start, use level_start(1) instead of functions like _read()