Parrallax maths?

0 favourites
  • 5 posts
  • If I have a tree sprite in a background layer that's parallaxing/moving at 60% of the speed, does that mean the tree should also be 60% of the size than if it were in the foreground at 100%?

    Hope someone understands how Z/perspective maths works!

  • I don't think the parallax speed has anything to do with the size, the Z position does however, as its further from the camera or at -zN it's size will be smaller, but i think that is already taken care off by Construct.

    As for how the math's work i have no clue but is basically the math's from isometric projection for the Z order part. the parallax is just moving left or right at a different speed than the camera against or with the camera direction.

    Hope that's what you meant.

  • The scale you showed is fine for a z, but yeah it doesn't really matter.

    A lot of games don't use any scale at all. I think it would only matter if you plan on doing any zooming.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Well, all parallax is is this:


    And the same with y

    Z scaling is basically

    X = f*originalx/z

    Where f is the focal length. I don’t know what value construct uses for that.

    There’s a bit more to it than that and usually they tie in the camera distance and relate it to the focal length. Also the perspective is around the center of the screen so we have:

    X = cameraZ*(originalx-screenCenterX)/(z+cameraZ) + screenCenterX

    Y is basically the same. Width and height are slightly simpler:

    Width = cameraZ*originalWidth/(z+cameraZ)

    As written, when the z of an object is unchanged then the position and size won’t change. Negative z is bigger and positive z is smaller. If that’s opposite then just make cameraZ negative. Smaller cameraZ values make more sever perspective and higher make less sever.

    I haven’t investigated but cameraZ may be something simple like 500, or if C3 has a way to change it, then use that value.

    Anyhoo I guess with all the above we can calculate the simulated z or scale of a certain parallax.

    And looks like you assumption is correct. The scale is equal to the parallax.

    On a side note if you wanted to do the parallax with z instead of a parallex layer you can do this:

    Z = cameraZ/parallexX -cameraZ

  • Thanks R0J0hound, and I figured out if I want to return an object to it's original size that's at parallax 60% and scale 60%, I can just divide the dimensions by 0.6!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)