How can I implement autoscrolling while allowing vertical movement using a Camera2D?

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

Image: here

  • Goal: Like Stage 4 of Gradius Gaiden shown here. Pretty much I’m trying to implement an autoscrolling background while also letting the player move vertically in the stage using a Camera2D. So far I have tried 3 different setups (see attached image) with the following results:

  • 1.) When the Camera2D scrolls/translates, the Player and ParallaxBG move as well. This is not what I want because the Player should not move with the BG, only the ParallaxBackground should move.

  • 2.) When the Camera2D scrolls/translates, the Player does not move and the ParallaxBG does move. This seemed to work fine until I made the Camera2D scroll up/down based on Player position limits. It seems to add the Player’s velocity with the Camera2D’s velocity; I’m not entirely sure.

  • 3.) When the Camera2D scrolls/translates, the Player/ParallaxBG moves as well. When the Player moves and the Camera2D does not move, the ParallaxBG will scroll with the Player. This is fine for player-driven movement, however, the ParallaxBG does not autoscroll if the Player is idle, for example.

  • Summary: The ParallaxBG will not scroll (with scroll_offset) if there is an active Camera2D in the Scene; and there doesn’t seem to be a way to override that behavior. Is there another way to implement this kind of feature? I’ve been reading about Viewports and might try something with that, but I wanted to run this by a few people before I go down that rabbit hole.

1 Like
:bust_in_silhouette: Reply From: exuin

You could place the camera on the player and constantly move the player forward no matter what button is pressed. Or use a shader to move the background instead of a parallax background node. Scrolling background - Godot Shaders

I definitely want to learn shaders eventually, so that might be a solution. I tried the constant movement trick you suggested, but it doesn’t quite work right when the Player moves horizontally because the ParallaxBackground will scroll forwards/backwards with the Player.

fighterwing989 | 2023-05-10 02:34