How do I make a sprite follow a camera

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

I’m making a game where the camera needs a sprite to follow it on the x axis, so that it always shows on screen. I have a KinematicBody2D for the player, and a Camera2D node as a child of the player, the main problem is that I can’t make the sprite follow the smoothing of the camera. I tried a lot of things already, including making the camera a scene, making the sprite it’s own scene, adding scripts to both the camera and the sprite, but nothing seems to work. I’m relatively new to godot so I don’t get a lot of how these nodes, scenes and other things work, so I’d like a bit of help.

:bust_in_silhouette: Reply From: njamster

Add a CanvasLayer-node as a child of your Camera2D and make the Sprite a child of this CanvasLayer-node, then set the position-property of the Sprite as you’d like.

:bust_in_silhouette: Reply From: Magso

There’s no need to make the camera or sprite an instanced scene. If both the Sprite and Camera2D are children of the KinematicBody2D, use move_and_slide to move the KinematicBody2D node. The smoothing in the Camera2D node will interpolate in global space.