#Explain parallax positioning to me like I'm a 5 y-old

8 messages · Page 1 of 1 (latest)

distant gyro
#

Hello!

I simply can't make sense of parallax positioning logic, both in Editor and at runtime.
Help me figure it out with this simple scenario:

Hard requirements (cannot be changed) :

  • The root node of the scene must be at (0,0) no matter what.
  • It contains a sprite that represents the ground. That sprite is 1000x1000 and its top left is positioned at (0,0) no matter what

For context, the player starts at (500,1000) (i.e. in the bottom middle of the "ground" sprite). In the drawing, I pretend the player is just one 1x1 px (I don't care about his width/height when I talk about his position).

The camera is 200x200 and is attached to the player. Therefore, it's properly positioned when the room starts. That's not part of this question.

How I set the parallax up:

  • Add a ParallaxBackground
  • Add one ParallaxLayer to it, with a scale of x:0,5 y:0,5
  • This ParallaxLayer contains one 100x100 sprite representing the sun

What I want :

  • When the scene hasn't started yet (Editor), the sun is directly under the player
  • When the scene has started (runtime) the sun starts directly under the player. Then of course it moves laterally when the payer moves, because of the parallax.

EXPLAIN TO ME LIKE I'M MENTALLY DISABLED :

  1. What calculations does Godot perform to position the parallax? What is the point of origin? Etc.
  2. Explain de difference (in this context) between **Transform **and **Offset **for the ParallaxLayers
  3. No matter what I do, I always end up using trial and error for those values. Explain!!!!!!!!!!!!!!!!!!!!!!1111!!!1111!!!!!!!!!! 🙂
distant gyro
#

bump

distant gyro
distant gyro
#

bump

ruby imp
#
  1. When it comes to positioning the parallax layers, Godot performs calculations based on the scale and offset values you provide. The point of origin for the parallax is the top-left corner of the root node, which you mentioned must be at (0,0). The parallax effect is achieved by moving the layers at different speeds relative to the camera movement.

  2. In the context of parallax layers, the "Transform" property determines the speed at which the layer moves relative to the camera. A higher X or Y value in the transform means the layer will move faster in that direction compared to the camera. The "Offset" property, on the other hand, specifies the initial position of the layer relative to the root node. By changing the offset, you can control where the layer starts in relation to the camera.

  3. Trial and error is often used when setting up parallax layers because it can be a bit tricky to get the desired effect. The values you choose for scale, transform, and offset depend on the specific effect you want to achieve. You can experiment with different values to see how they affect the layer's movement and position. Adjusting the scale of the layer will determine how much it moves relative to the camera, while the transform values control the speed and direction of movement. The offset helps you position the layer initially.

hope this helps!

distant gyro
#

It's a good start!

But it's all just general principles which I already understand. I was more hoping for a step by step explanation of the positioning.

So far I've come up with the following principles; when I stick to them it makes my life much easier.

  • Leave the ParallaxBackground's "Transform" position at (0,0)
  • Moving the "base offset" of the ParallaxBackground is like moving the overall scroll origin away from (0,0) ; that's what we're after.
  • It's pointless to change the "Transform" values of the ParallaxLayers. Just leave them always at (0,0) to avoid mistakes.
  • Once the ParallaxBackground's "base offset" has been decided, only work with the ParallaxLayers' "offset" to decide their position at startup.
distant gyro