Godot Version
v4.2.stable.official [46dc27791]
Question
I’m trying to make the player camera smoothly move in front of the player if they accelerate. Unfortunately, if I try to use the move_toward
command to make this work, the camera movement doesn’t happen.
VIDEO DEMONSTRATION (Too big to be put on post, sorry)
First clip shows the intended behavior without smoothing; second clip shows my failed attempt to add smoothing using move_toward
.
Camera code:
extends Camera2D
@onready var player = %Player
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
if player.alive:
if abs(player.velocity.x) > player.SPEED:
#position.x = player.position.x + (100 * player.directionX)
#position.x = move_toward(player.position.x, player.position.x + (100 * player.directionX), 50)
position.y = player.position.y
else:
#position.x = player.position.x
#position.x = move_toward(player.position.x + (100 * player.directionX), player.position.x, 50)
position.y = player.position.y
NOTE: There are two lines for the camera’s X position that I intentionally commented out on this post.
The top line is the intended camera behavior without smoothing.
The bottom line is my failed attempt to smooth the camera’s movement using move_toward
.