How do I change the object the camera’s following using the AnimationPlayer node?
So, here’s my setup:
I use the CutsceneManager to animate and change various properties for a cutscene. When the player enters the “Cutscene” Area2D, it will play the animation. And because I want the camera to be static in the meantime, I made this code on the Camera node:
extends Camera2D
@onready var player = $"../Player"
@export var follow: Node2D
func _ready():
follow = player
func _process(delta):
position = follow.position
And so, in the AnimationPlayer, I set-up keyframes to change this variable to follow a specific point, like so:
The problem is: when I change this value to follow the player again, instead of following it, the camera just stays still at the player’s initial position when it entered the scene.
Does anyone have a fix or any suggestions on how to approach this better?
Thank you!
I believe a good way of solving this is instead of changing wht the camera is following, change what object is camera the child of. So, at the start, for example, the camera is a child of the player - aka follows player, but when you want it to follow a different object, you:
Oh one thing to note though, I believe removing it from the tree with nodename.remove_child() will remove the camera from* the viewport or swap to another in the tree if you have another one enabled, so set it back to this camera after adding it as a child on the new parent call cameraname.make_current() on it!
Got it, I was just figuring this in my head, but I think you should use: remove_child() before add_child(), basically remove from current parent and add to the new one. Tell me how it goes
You should probably create a new animation player for the camera separately. Because it just refers to the default transform properties. Without changing the position. There nothing else that seems wrong there.
It’s also referring to the first frame of the animation, the track time of 00:00 where the transform properties are default to player initial position. It looses the camera signature after reloading. And, just goes back to frame one. The would probably be some temporary locations of the camera track. That you would be able to rewind and forward to. Where the camera would be just stalling on the previous camera locations. Or, not.