Godot 4 Parallax Scrolling

Godot 4 Parallax Scrolling

Scene Setup

Start by creating a new 2D scene in Godot.

  • Root Node: Use a Node2D or Main as your root.
  • Add a Camera2D: This will Control the view and trigger the parallax effect.

Add ParallaxBackground

  • Right-click the root node and add a ParallaxBackground node.
  • This node manages the parallax effect and tracks the camera.

Add ParallaxLayer(s)

  • Add one or more ParallaxLayer nodes as children of ParallaxBackground.
  • Each layer will scroll at a different speed to simulate depth.

Add Visual Elements

  • Add Sprite2D nodes as children of each ParallaxLayer.
  • Assign textures (e.g., clouds, mountains, stars) to each Sprite.

Configure Motion Scale

  • Select each ParallaxLayer and adjust the motion_scale property:
    • Far background: Vector2(0.1, 0.1)
    • Mid background: Vector2(0.5, 0.5)
    • Foreground: Vector2(1, 1)

This controls how fast each layer moves relative to the camera.

References

[1] docs.godotengine.org