Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Discussion Best workflow for creating 2D environnements with Parallax ?

Discussion in '2D' started by PaulMDev, Dec 27, 2022.

  1. PaulMDev

    PaulMDev

    Joined:
    Feb 19, 2019
    Posts:
    68
    So I've been doing a Hollow Knight ripoff recently as a learning exercise, and I want to create a parallax effect to give my environments volume.
    I was planning of doing it by having a script on each layer that move them according to the camera position and also scale them down, so that I could still have a rough idea of were objects will be positioned when the camera will be close to them.
    But recently I learned that when making Hollow Knight the devs actually use the Z-axis and a perspective camera to create depth. And now I'm completely reconsidering my current architecture for environments.

    I looked at how Unity did it in the Dragon Crachers demo, and they have all layers on the same depth and use a script for parallax, but they don't scale the layers so it's impossible to know in advance where an object will be without pressing play.

    So, what do you think ?
    Is it better to move objects with a script or to rely on perspective?
    And should I use the Z-axis for occlusion or only the Sorting Layer system ?
    Even then Sorting Layers can always be used for 2D Lights, but is it good practice to have layers on a different depth even if we don't use it ?

    Since the answer will probably be different depending on the requirements, know that I'm not using a lot of tilemaps but mostly sprites placed everywhere and overlapping each-other. My goal is not to have the simplest or fastest workflow but the most flexible one while still having good performance.
     
  2. Lo-renzo

    Lo-renzo

    Joined:
    Apr 8, 2018
    Posts:
    1,328
    Perspective is probably easier for workflow. While it is possible to emulate parallax with scripts and some games take this approach, perspective with z-spaced objects makes it all happen automatically and intuitively.

    Script-based parallax may be useful if you want an orthographic camera and/or can't use a perspective for some reason.

    There's not going to be a significant performance difference between the two approaches.

    Sorting Layers: you may still want to use these in addition to z-spacing your objects purely so you can apply lights differently between your foreground and background layers. I would probably simply decide to have something like 7 layers, spaced in z, but also - for lights - give each one a different Sorting Layer.