How to make a teleport look like it isn't a teleport?


Hello! I am trying to “animate” when a player is rescued from water, and having some trouble making it look how it should.

Currently, I have a little helicopter sprite spawn above the player, and the player teleports to the respawn point. However, I want it to look like the player is slowly moving from where they touched water to the respawn point. However, I can’t seem to really find any information on this? Any research on interpolation just leads me to smoothening gameplay (which was helpful! Just not for this!) and I couldn’t seem to find any other methods for this.

Should I be trying to use linear_interpolate()? Or tweens? Or something else?

Any interpolation would work. Easiest is

Player.position = position.lerp(restart_position)

Do this while the animation plays.

Oh I see. How do I tie it to the animation? I have an animation that lasts 3 seconds, and I have a function that has “$Player1.position = position.lerp(p1Spawn, 1)”.

So, after I tie the lerp to the animation, it should automatically make it smoothly teleport there over the course of the 3 seconds, correct?

You would want a use a smaller then 1 lerp step. Set the position many times in a physics process function.

Lerp step of 1 will make the jump in one frame. A lerp step of 0.1 will take 10 frames, a lerp step of 0.01 will take 100 frames or around 1.6 seconds.

Oh I see, so I just have to figure out how to call the function 100 times. Do you have any recommendations for that?

func recover_player1():
var counter = 0
while counter < 100:
$Player1.position = position.lerp(p1Spawn, 0.01)
counter += 1

This seems to just crash the game.

var recover : bool = false

func _physics_process(delta):
  if recover :

func recover_player():
  $Player1.global_position = $Player1.global_position.lerp(p1Spawn, 0.01)
  if $Player1.global_position.is_equal_approx( p1Spawn ) :
     recover = false

recover would be set to true when player one falls into water

or if you want a tween, when player falls into water. (I like this better)

var tween = get_tree().create_tween()
tween.tween_property($Player1, "global_position", p1Spawn, 2) # 2 second tween

I just wanted to let you know that I was able to get this working perfectly thanks to your help! Thank you so much!

1 Like