Godot Version
4.6.2
Question
I have a 2D topdown game where my camera used to be a child of the player (which is a rigidbody2D), but i read that it is soother if the camera is a separated and its movement is updated in _process. Unfortunately all the examples I’ve found were for 3D cameras, so I’ve tried to make due but have mostly failed.
Here is what I have so far:
extends Camera2D
@export var player: PlayerVehicle
var __target_pos: Vector2
func _ready() -> void:
if not player:
push_error("Combat camera wasn't assigned to player")
return
__target_pos = player.global_position
func _process(delta: float) -> void:
__target_pos = lerp(__target_pos, player.global_position, min(delta, 1.0))
self.global_position = __target_pos
It doesn’t need to rotate or anything, it just needs to move position.
It technically works, but it lags far behind the player and needs to play catch-up. What am I doing wrong here?
I also think I recall seeing a post awhile back saying that using lerp() in _process isn’t a great idea. Is there a better alternative?
Thanks!