- Edited
I'm running a script every physics frame to check if the player is looking at an object. Then I want to display a HUD item using the AnimationPlayer. Here is what my code looks like:
func _physics_process(_delta):
if get_collider():
is_looking = true
else:
is_looking = false
update_hud()
func update_hud():
if is_looking:
$AnimationPlayer.play("Use")
else:
$AnimationPlayer.play_backwards("Use")
The problem with this method is that every frame, it plays the animation from its 1st keyframe. I thought a bit about it, but couldn't find a good method of achieving this. How can I achieve such thing? Are there better methods of doing this?