← Pixel Dreamer Studio

Keep a smooth follow camera, but jump with the player when they teleport

Treat a move too big for one frame as a teleport and snap the camera, or call snap() yourself.

A follow camera that lerps toward the player looks good while walking and bad after a teleport, a respawn or a door to another room. In our Godot 4.7 test the player walked at 8 m/s, then teleported 200 m. The lerp camera was more than 1 m from where it should be for 63 frames, 1.05 s, flying over everything in between. The script snapped on the teleport: 0 frames off, and the same 1.53 m lag as before while walking.

The code

Put the script on your Camera3D, set target to the player and tune offset and smoothing. Call snap() right after you move the player yourself. A move of more than teleport_distance in one frame snaps on its own.

extends Camera3D
## Smooth follow camera that jumps straight to the player after a teleport,
## instead of sliding across the whole level.

@export var target: Node3D
@export var offset := Vector3(0, 6, 8)
@export var smoothing := 5.0
@export var teleport_distance := 5.0  # a move bigger than this in one frame counts as a teleport

var _last := Vector3.ZERO


func _ready() -> void:
	snap()


func snap() -> void:  # you can also call it right after you teleport the player
	global_position = target.global_position + offset
	_last = target.global_position


func _process(delta: float) -> void:
	if target.global_position.distance_to(_last) > teleport_distance:
		snap()
		return
	_last = target.global_position
	global_position = global_position.lerp(target.global_position + offset, 1.0 - exp(-smoothing * delta))

What we measured

Walk at 8 m/s for 2 s, then teleport 200 m, at 60 fps with smoothing 5. Two runs with the same numbers.

Why it happens

Smoothing closes a share of the gap every frame, so 200 m takes as long to close as any other gap, and the camera shows the level on the way. A lerp cannot tell a fast run from a teleport. The distance moved in one frame can.

What to change

Why the smoothing uses exp(): lerp at the same speed at any frame rate. Shake on top of the follow, without the follow code wiping it out: 3D camera shake. Torches along the way that flicker the same on every screen: torch light flicker.

A teleport effect to go with it: Pixel Art 3D VFX for Godot 4 has 40 pixel art effects for 3D games, including Coin Collect, Collect Star Burst, Item Glow, Level Up and Teleport.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Pixel Art 3D VFX for Godot 4 has 40 pixel art effects for 3D games, including Coin Collect, Collect Star Burst, Item Glow, Level Up and Teleport.

More how-tos for Pixel Art 3D VFX for Godot 4: A torch light that flickers the same on every screen

More how-tos: Game feel