- Home /
Most efficient way to achieve 2D parallax effect with orthographic camera?
I am currently making a 2D game with an orthographic camera. I have different "layers" that I am trying to manually give parallax. I know the logic behind it is simple, but what is the most code-efficient way of achieving this? I'm thinking of some parallax script that I can just attach on each layer, but I would like it to run smoothly on mobile. Anyone have any suggestions? Thanks!
Answer by vxssmatty · Sep 08, 2011 at 03:44 AM
Click on your 'Parallax' tag... read the questions asked before with it and see if that helps you...
How i generally do it though;
Player or Enviroment has a movement/speed property - I choose one to be the 'Master'
Then i create a script that controls movement of the other object (texture offset, geometry, etc) and also control limits that i might want to impose, then i read the speed from the 'Master' and multiply that by a float (0.5) to get half the speed... substitute the float to change rate.
Your done :)
Does your camera not move at all then? Is your camera stationary and you just scroll your elements?
I think he meant move the background scene items relative to the cameras position and the cameras position tracks to the players position. So in other words the foreground objects are normal but the background objects move in a negative relation with the camera with movement speeds decreasing depending on how far away they are supposed to be.
But how can I simply track that? I can't just have my background layer equal, for example, to half of the cameras position. I feel like this is such a simple task, yet I have no idea why I'm struggling in getting it to work. I just have it so each layer has this script (psuedo-code) attached:
thisTransform.position.x = -mainCamera.transform.position.x * speedX; thisTransform.position.y = -mainCamera.transform.position.y * speedY;
Should this be working?
Yes that is basically how i did it, its a very simple way to do it, you can even grab the distance from camera to create an auto script for layers so anything you position will automatically have the right speed parallax relative to other assets positioned in z-space.
This solution has a performance problem on mobile platform in my experience. I find a solution but it didnt give that effect.
I write a solution of my experience here.
Answer by BASICSPACE · Jul 02, 2014 at 10:09 AM
Here's a script that will allow you to create parallax layers of transparent seamless textures in front or behind your scene. Its's designed especially for the orthographic camera. https://www.assetstore.unity3d.com/en/#!/content/18342
Your answer
Follow this Question
Related Questions
Background Image as Orthographic 2D Game Background - and quick 2D parallaxing question 1 Answer
My parallaxing is moving by it self? 1 Answer
parallax scrolling using orthographic camera 1 Answer
Dynamic Orthagraphic Camera Zoom 1 Answer
2D Camera Question: Pixel Perfect W/O Cutting Bottom Edges 1 Answer