Search Unity

Question (2D) How do you handle parallax with large scenes with multiple areas that need it?

Discussion in 'World Building' started by PixelPockets, Dec 1, 2022.

  1. PixelPockets

    PixelPockets

    Joined:
    Sep 7, 2020
    Posts:
    143
    The concept of parallax and getting it to work is rather simple, but I've found that I've run into a bit of a problem I'm going to need to solve, eventually.

    In my project, I have one large scene with several different areas; some of which will need to have some form of parallax being done in the background. Creating the parallax effect is the easy part, but with multiple different areas, all with different levels of parallax going on, how would one define a "center" point so that the background doesn't end up off screen when you enter a specific area?

    By that I mean, at what point do you define where the parallax begins and ends? Do you create trigger points in each area that will reset the background sprites to a specific position so that the effect stays constant, even if you leave that area and come back? What about areas that have multiple entry points?

    I'm just curious what solutions you have come up with to make sure the parallax remains consistent across a larger scene, while going in and out of a parallax-ing area?
     
  2. wmgamble

    wmgamble

    Joined:
    Aug 26, 2021
    Posts:
    1
    Sad that you never got an answer friend. Especially because I'm trying to do the same thing, haha. I think I'm likely going to create cavelike pass-through areas that separate the "parallax zones" and enable/disable them as the player is passing through the (non parallax) caves. I do wonder if there's a better way.
     
  3. PixelPockets

    PixelPockets

    Joined:
    Sep 7, 2020
    Posts:
    143

    Actually, I gave up on any sort of ideas regarding paralaxing larger areas in code, and just switched to using a perspective camera. There's some drawbacks, but honestly, it hasn't been noticeable in my particular case, and paralax is much simpler to handle. You don't need to worry about any code. You just place your background/foregound tiles as you normally would, possibly offsetting them from each other slightly, change their Z positions, and let the camera do the work. As for the drawbacks, you'll need to figure out things like particle system shapes, as some shapes can look odd when moving the camera. There's some others, but I won't get into them here.

    You could always have two separate cameras, ortho and perspective, but that also comes at a cost. However, it's something to consider if you can spare the slight performance loss. I did it this way for a bit, but found that using a perspective camera alone was just a simpler way to handle things.
     
    Dark_Seth likes this.