camera2d follows player while sticking to path of path2d?

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

is it possible for camera2d to stick on path2d while following relatively to player’s position?
if so, how to achieve it?
something like this:
the illustration of what I want to do
in this illustration, the player is off-center from camera on x-axis, but centered on y-axis because the camera sticks in the path


the reason behind is because I want to move my player on not straight room and I want to fix a camera on certain axis on certain sections (like move only on x axis on straight right room).
at the moment I have no idea what to do other than changing camera’s limit and detect using area2d per sections to change the limit, but it’s not good enough as intersecting areas wont be able to get transitioned smoothly. the camera will snap into other section after going little bit far from the current area

Interesting question. Yes, you can try to stick camera to the Path2D, but there is another approach: Making a camera KinematicBoby and set up StaticBody boundaries. Note, that collisions shoud be set on another layer.

USBashka | 2022-07-16 09:32

  1. so any idea how to make camera sticks to path while following player too?

  2. is there a difference between using Tilemap as a static collision and StaticBody? also using this similar method, if it’s too tight to camera, it wont move at all. but making a gap for the KinematicBody to move will show the area i don’t want to get shown

neorocket64 | 2022-07-16 10:23

  1. Somehow find the closest point to the player position on path. Sorry, can’t give realisation
  2. Yes, TileMap will also work. Yeah, that might be a problem. The possible solutions is making really small gap or just paint out of bounds area with black (as it done in Undertale) or make something like background. Also note that at different screen ratios the camera can have different sizes, so you shoul add background.

USBashka | 2022-07-16 10:37

alright thanks for the respond
yes, adding the filler like background or just fill with tilemap is the way for KinematicBody method. but my problem is having those areas
shown at all. i want to have it tight and only show certain areas, but i guess it’s too much for that node since the camera can get weird if it hit by some collision while trying to positioned itself to player

neorocket64 | 2022-07-16 10:49