A Smooth Camera
Part of the Game Feel section of Coddy's Godot journey. Lesson 10 of 23.
A camera fixed to the player starts and stops with sudden jerks. A camera that trails a little behind and then catches up moves more softly.
Camera2D does this with position smoothing.
position_smoothing_enabled = true
position_smoothing_speed = 4.0The first line turns smoothing on. The speed sets how fast the view catches up. A small number trails far behind, and a big one hardly trails. Godot's default is 5.
The camera node still moves with the player. Only the view on screen lags behind.
Challenge
EasyMake the camera catch up smoothly.
- In
_ready(), setposition_smoothing_enabledtotrue. - Set
position_smoothing_speedto4.0, and keep the limits.
Press Play and run: the view trails behind, then catches up. Then Check.
Try it yourself
extends Camera2D
func _ready():
limit_left = 0
limit_top = 0
limit_right = 1600
limit_bottom = 360
All lessons in Game Feel
Practice on your own: Godot playground