How would I put a slight delay on a Camera2d?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By connortbot

I saw a previous question asking about how to make the camera follow the player but with a delay, giving it a bit of a bouncy look. The answer was to use an InterpolatedCamera, but that’s 3D.
I haven’t found any methods that I can use in Camera2d, so how would this be achieved?

:bust_in_silhouette: Reply From: kidscancode

All InterpolatedCamera in 3D does is lerp the camera’s transform. You can do this in 2D yourself with something along these lines:

extends Camera2D

export (NodePath) var target_path
export var speed = 10
var target

func _ready():
    if target_path:
        target = get_node(target_path)

func _physics_process(delta):
    position = lerp(position, target.position, speed * delta)

You can play around with how you move the camera depending on what effect you want. It’s really just about moving the camera independent of, but linked to, the target.

:bust_in_silhouette: Reply From: scrubswithnosleeves

Answered this live on stream: https://www.youtube.com/watch?v=fC3384meGZA
should be around 2 hour 25 minutes or so.

Idk if this is what you are talking about, but you can set drag margin enabled on a camera 2d, then set the margin to be 0, and then turn smoothing on.