Can't snap player after tween

Godot Version

4.4

Question

Hi all, I am trying to move my player by tweening from point to point. I have door areas where I want the player to snap(teleport) from one side of the door to the other instantly. This should be simple, I just do “self.position = location”

except nothing happens. No matter what I try, the player does not move. What is weird is that if i click again to move, that is when the player does instantly snap to the location. Its not a time based thing, but for some reason even though I tell the player to move, it refuses to move until I move again, then it instantly snaps.

What is going on?

CODE:

func tween_to_node(pos: Vector3):
var offset_position = Vector3(pos.x, 0, pos.z)
var height = GAMEMANAGER.core.terrain.data.get_height(offset_position)
target_position = Vector3(offset_position.x, height, offset_position.z)

tween = get_tree().create_tween().bind_node(self).set_trans(Tween.TRANS_LINEAR)

tween.tween_property(self, "position", target_position, 1.2)

That is the code to do the tween movement. Super simple, works fine. Here’s the code that gets called (by the door) to “relocate” the player:

func relocate_to_node(pos: Vector2i):
var offset_position = Vector3(pos.x, 0, pos.y)
var height = 4
var relocate_position = Vector3(pos.x, height, pos.y)

So what is the problem?

If your door movement script is called before the tween is finished the end result will be the player at the final tween position.

That might be part of it. I tried stopping the tween to test that and it didn’t work. But I might have been stopping the tween improperly.

Is there a proper way to stop the tween? Is there a way to stop the tween then make sure the snapping happens?

If the player movement lands him on the door, relocate the node in a callback at the Tween’s finished signal.
tween.tween_callback(move_if_player_is_on_door)

1 Like