How do you make a Path2D/PathFollow2D follow a Camera2D?

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

Path2D/PathFollow2D - Camera2D Path2D/PathFollow2D - Camera2D - Album on Imgur

As you can see, I have a Camera2D following the Player, and I also want to have the Path2D/PathFollow2D staying outside of the camera viewport, such that NPCs/enemies can spawn outside of view before coming into the fray.

Tree Imgur: The magic of the Internet

I have tried placing Path2D/PathFollow2D as a child of the Camera2D node, but it remains static and NPCs are spawning from the same place.

How can I make the Path2D/PathFollow2D follow the camera and remain outside of the viewport?

in code set the vector/location of the object to some offset of the camera.

camera_vector + offset_vector.

LordBoots | 2022-12-03 21:53

Thank you for the suggestion. I want to achieve a consistent boundary around the camera, such that it is always outside of the viewport. Wouldn’t I have to calculate the camera’s position relative to the world map, and then select a random position based on that?

BlackBladedAxe | 2022-12-03 22:21

Shouldn’t have to, no. You should just be able to use the camera’s .translation to get the position of the camera. Pretty sure it stores this variable as a reference to it’s location in “space”

LordBoots | 2022-12-03 22:25

I cannot find “translation” as either a property or a method in Camera2D’s documentation.

BlackBladedAxe | 2022-12-03 22:28

You should be parenting your camera to a kinetic body node. The camera doesn’t have a translation variable.

set it’s parent to a kinematicbody2d and then use that to move the camera instead.

LordBoots | 2022-12-04 11:51

This was already the case. The issue wasn’t having the camera follow the Player body, but to have NPCs spawn outside of the camera viewport. It’s moot now, as I’ve created a custom solution via script. Thank you for responding to my questions, though.

BlackBladedAxe | 2022-12-05 20:52