
.png)
#PARALLAX EFFECT UNITY 2D CODE#
To clean up the backgrounds, I just check if the Player is in front of one of the backgrounds and if not then delete it.īelow is the working parallax code along with the attempted infinite background code at the bottom: using System. Then: Create a copy of the current background and place it to the right the current background. I can't even begin to list the things we. Only downside is that UnityEditor will give you a bad time all the way. Code (CSharp): using System. Just remember to set ansparencySortMode to Orthographic for best results. Hey guys, to get a dynamic background for our 2D-plattformer, we have a scrolling background script which basically coordinates the backgrounds and creates a parallax effect. Like you said, perspective cameras will give you parallax for free. If: Player position is outside the bounds of the current background on the right. We use perspective since we use parallax heavily (think Ori, sans the pretty art).
#PARALLAX EFFECT UNITY 2D HOW TO#
Then: Create a copy of the current background and place it to the left the current background. Learn how to create a main menu and a parallax background that moves based on your mouse cursors position using Unitys UI in this 2D Top Down RPG Game Dev. If: Player position is outside the bounds of the current background on the left. The extra depth effect is achieved through the use of a. My process for creating the infinite background is as follows: Loop: Through all the background images and do the following checks: Parallax Normal mapped is the same as regular Normal mapped, but with a better simulation of depth.

That didn't work very well so in my current version, I'm using cameras to detect the Player's position. I've used GameObjects attached to each background object and compared them to the Player's position.

I've tried a few different ways to detect that the player is in front of the background. The main problem is that out of my 11 backgrounds used for the parallax effect, only the first one ever gets cloned and none of them get destroyed when off screen(Although this is more of a secondary concern at this point). So: transform.position new Vector3 (startpos + dist, ypos + ydist, ) Some other things, if that didnt fix your problem: If you want the clouds to just move to the right, no need to add offset to ydist If you set speed to 0 in the inspector, the clouds will just have a standard parallax effect without moving to the right. The Player can jump and move up and down but the background and camera Y position stays constant. I should mention that the camera backgrounds are restricted movement on the X axis only.
#PARALLAX EFFECT UNITY 2D FREE#
I have gotten the parallaxing to work but I start to run into issues when trying to make the background continue infinitely. Free Parallax for Unity (2D) Free Parallax for Unity (2D) FREE.
