A downloadable tool

Download NowName your own price

What is Parallax?

Parallax is an easy way to make your backgrounds (and foregrounds!) move with your camera. Parallax works with the standard Unity Camera and Cinemachine.

Setting Up Backgrounds:

First things first, you can setup your backgrounds however you like, this is just my preference.

Create an object called “ParallaxScenery” and children of each “depth” of backgrounds and foregrounds. I’ve found 9 different depths are all I need. I’ve named them like this:

I also attach a “Sorting Group” to each object correlating to the depth.

Again, this step isn’t necessary, you can adapt the script to your project.

Setting Up The Script

You only need this script on one object in the scene. If you created “ParallaxScenery” that’s where I put it, but you can throw it on your camera or any object you want.

Now, let’s set up the Parallax Script settings. Head over to your inspector and it should look like this:

Drag your camera to “Stage Camera”. 

Vertical Restriction will restrict the parallax effect when your camera moves vertically. I’ve noticed 0.5 works nicely for me. 

1 means the script will not affect the Y-axis.

0 means the script will move the Y-axis the same as the X-axis.

Next, let’s open up the array of Layers by clicking the arrow

The “Size” is how many layers you’re going to have in your scene. This can change from scene to scene, but for this example I’m going to do all 9 that I’ve been using.

Each element has a few things you need to do. Go ahead and open one up.

Name is whatever you want to name it. If you’re following my ParallaxScenery convention, just name it the same as each layer. Drag your layer object here and set it’s distance to the camera. 

1 is the furthest you can be from the camera, and -1 is the closest you can be to the camera.

Note:

If you choose 1, it will lock the object to the camera’s position.

If you choose 0, it will appear the same as your regular stage.

Example distances are as follows:

Static = 1

Farthest = 0.9

Farther = 0.75

Far = 0.5

Behind = 0.25

Ahead = -0.1

Close = -0.25

Closer = -0.5

Closest = -0.75

The layer objects are -not- locked to the depth of the objects. You will need to control that with your own conventions. I use Sorting Groups attached to each object. The nice thing about this script is you don’t need to sort the Layers in order so if you come up with a new layer during development you don’t need to start over with the Parallax script.

Use with Cinemachine 

Using this script with Cinemachine works with as much as I’ve tested so far. You need to set your CinemachineBrain’s Update Method to “FixedUpdate” and Blend Update Method to “FixedUpdate”

Important: 

When you drag your Camera to the script, drag your ACTUAL camera, not the virtual camera. 

If you use a virtual camera it does not listen to the positions properly if you have a Cinemachine Confiner attached.


Download

Download NowName your own price

Click download now to get access to the following files:

Parallax.cs 1.7 kB

Comments

Log in with itch.io to leave a comment.

Thank you it was a good tutorial, I loved this parallax especially in the y movement. I'm a beginner, and I have a question. Please I really need this, how do I make it infinite?

I am so sorry this is a late reply, but maybe you're still working on things. This effect wasn't intended to be a "forever" effect. you'd need to program your items to "zap" back to the 0th value after moving in the x direction. I have abandoned Unity since they went public and they made everything crazy slow and clunky :(

(+1)

Worked perfect thanks!

Awesome!

This works well and is very easy to understand. The fact that it's usable with multiple vCams is great too, especially since no tutorials go over that. Since your script requires the Main Camera with the brain, I decided to try and it worked:

Ahh! That's awesome! I'm glad it worked for you ^_^