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.
- Lerp only: biggest lag while walking 1.53 m. After the teleport, more than 1 m off for 63 frames, 1.05 s.
- The script: 1.53 m while walking, 0 frames off after the teleport, 1 snap in all.
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
- Very fast movement can count as a teleport at low frame rates: 5 m in one frame is 150 m/s at 30 fps. Raise teleport_distance for fast games.
- Fade to black around the snap if the cut feels too sudden.
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
- A swing that settles the same at any frame rate
- Screen shake that returns to center
- 3D camera shake that lands back on center
- Hit stop and slow motion
- Confetti particles with random colors
- Choppy particles: fixed_fps and interpolate
- Play animations in 12 steps a second, at the right speed on any screen
- Make a harvested crop pop out in an arc
- Shake a rock or tree when hit, without it drifting
- Pickups that fly to the player in the same time at any frame rate
- A cooldown that waits while the game is paused
- Keep attack presses made just before the swing ends
- A dash that covers the same distance at any frame rate
- A hold-to-craft bar that takes the same time at any frame rate and finishes once