Godot Version
v4.4.stable.official [4c311cbee]
Question
`I’m trying to make a first person grid based, dungeon crawling game like Wizardry, so I got a multilevel dungeon and staircases that act as teleporters to move from one floor to the other. But on getting teleported, the player immediately starts getting dragged back to his original position. When I was trying to get the player to spawn in on the “starting” location, I also had this problem with the player getting dragged to (0, 0, 0) but I’m not even really sure how I fixed it. I think it has something to do with player movement.
Player.gd Player.gd - Pastebin.com
TeleportStairs.gd TeleportingStairs - Pastebin.com
The second pastebin link doesn’t work, so I can only imagine what teleportstairs is doing. However, I imagine move_towards_target(delta)
in your player’s _physics_process
is bringing your player to var target_position = Vector3.ZERO
, especially if in TeleportStairs you are instantiating a new player, or otherwise resetting the target position to zero.
But this is a question you should be able to debug on your own with print statements. I say this specifically here because the code is so short. For example, change _physics_process
to look like
func _physics_process(delta):
if not can_move: # Prevent movement when teleporting
print("Can not move")
return
if not move_in_progress:
print("Move not in progress")
handle_input()
move_towards_target(delta)
And in move_towards_target, print the current position and target location. Check what the logs look like when you get teleported. Remove print statements that are too noisy, and repeat until you get a grasp of what’s going on.