Reputation: 21
I am new to Godot 3.5.3 and need some help with an issue I've been having.
I am trying to make a 2D train platformer with a parallax background (with all of its layers) constantly move horizontally right to left to give the visual of the train moving fast. I want the camera to follow the player walking on the train without the camera affecting the background. When I make the camera targeting the player current, it makes the background "seize" and when I move the player the background just scrolls in the direction and speed of the player.
I just want the background to keep scrolling in the back no matter where the player is on the train but with the camera also focusing on where the player is on the train following him
I've tried searching up on stack, Godot documentation, YouTube, forums anything that could be potentially related to my problem. I've found a few that were very similar such as people having issues with offset but nothing that was related to my problem or a problem with an answer that could solve my issue.
I don't have any code I could provide since I am not sure if my issue is something that has to be solved with a script or not so the only script I have for either the Camera or Background is for the ParallaxBackground's scroll:
scroll_offset.x += 40*_delta
As mentioned before I am very new to Godot and don't have much experience but any help would definitely be appreciated!
Upvotes: 2
Views: 409
Reputation: 40
As per this reddit comment, setting ParallaxBackground.scroll_base_offset
did the trick for me.
This would be your code:
scroll_base_offset.x += 40*_delta
Godot docs: ParallaxBackground.scroll_base_offset
Upvotes: 1
Reputation: 2705
It's by design: https://docs.godotengine.org/en/stable/classes/class_parallaxbackground.html#class-parallaxbackground-property-scroll-offset
Calculated automatically when using a Camera2D, but can be used to manually manage scrolling when no camera is present.
You can however set the scroll_offset to a specific value, even if you can't include scroll_offset in the actual calculation.
Also, the ParallaxBackground node needs to be a child node of the Camera2D node.
extends ParallaxBackground
@onready var offset_x = 0.0
func _process(delta):
offset_x += 40 * delta
scroll_offset.x = offset_x
Upvotes: 0