Search Unity

Best way to implement 2D parallex effect

Discussion in 'Scripting' started by mahdiii, May 15, 2019.

  1. mahdiii

    mahdiii

    Joined:
    Oct 30, 2014
    Posts:
    856
    Hi. Which one is better or if none of them, please share your approach
    1- Moving sprites in terms of distance to the camera
    2- Using a perspective camera instead of the orthogonal one and put sprites in different depths
    3- Moving several cameras rendering different layers (background, middle, foreground, etc)
    I prefer the third way.
     
  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    This strikes me as one of those questions where there simply is no 'one true answer'.

    Having said that, on first reading, my immediate thought was 1 or 2. 3 just seems like a bit more hassle to me. But I suspect this is as much a case of personal preference as anything else as there are going to be different pro's and con's with each approach.

    If your instinct is to go for 3, then try it out and see how it goes. It shouldn't be too difficult to adjust if you change your mind later on.
     
    mahdiii and lordofduct like this.
  3. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,537
    Yep... no one true answer.

    It depends what visual style you want.

    If I was making a 2d style game and wanted to have that old school 2d parallax effect. I'd move the various layers of sprites at different speeds just like oldschool parallax does it.

    Where as the perspective camera approach is going to have a lot of different implications. It'll give everything the perspective look as it's true perspective projection rather than scrolled layers.

    To get that "farther distances scroll slower than near" you'll have to actually have those layers that far away. This will have ramifications from a draw distance perspective, as well as detail of those sprites since they'll be so far back.

    But this may work if your scrolling scales meet your needs.

    In the end though... use the technique that works for your exact visual requirements.
     
    mahdiii and Doug_B like this.