- Home /
Perspective Camera on only one axis.
Hi everyone, I'm creating a 2D game with a parallax background. I am using a perspective camera to do this. I'm looking for an effect where ONLY the X-axis is effected by the perspective camera, and the Y-Axis is not.
I know this can be done with an orthographic camera and scripts that manually move the objects, but it just makes things simpler to use a perspective camera. Anyways, is there a way to make a perspective camera perspective on the X-Axis and orthographic on the Y-Axis?
Thanks for the help!
Can you describe what you mean in more detail? ie. If I use the camera you are describing to render a cube, what does it look like, if I put the cube on the left edge of the screen? On the right? At the top? etc.
Sure, sorry - I probably could have been more descriptive...
I have say 100 sprites in my scene (it's a Unity2D game). I have 5 layers, one main layer that pans with the camera (no parallax), 3 layers behind the main layer (these layers progressively go slower as they get further back), and one layer in front of the main layer, which moves faster than the main layer. Now, I want all the parallax effects that I am describing to happen when the camera moves left to right. What I don't want to happen, is any parallax effect to happen when the camera moves up and down. I want all of the layers to move up and down the same exact difference....
Does that make more sense? I know I can create a script that does this, using an orthographic camera. 1) I am not sure of the performace hit this will take. 2) that seems like a more complicated approach.
Anyways, thanks for the help!
What is the reason you want to use a perspective camera? I'd honestly do this with an orthographic camera, unless there's some effect you really want to have be in perspective.
All you'd have to do to get parallaxing with a perspective camera is move the layers backward or forward in space. The perspectival nature of the camera will take care of the rest. Unfortunately, this comes with the added effect of working both horizontally and vertically. You could probably write some script to account for, and negate the visual effects of vertical camera movement, but this seems like an overly complex solution to your problem ( something along the lines of this ).
However, the solution when using an orthographic camera is simply:
void Update () {
transform.Translate ( cameraPositionChange.x * layerNumber, 0, 0 );
}
I actually just tested it and the orthographic scripts seem to hurt performance greatly, dropping FPS from 60 to nearly 30 when I move the camera. If I use a plain old perspective camera, the performance is hardly dropped when the camera moves.
Can you post the script you're using? This doesn't seem like something that should be performance intensive.
Your answer
Follow this Question
Related Questions
Why is my parallax effect glitching out with my perspective camera? 1 Answer
Vertical Perspective / Horizontal Orthographic 1 Answer
Can I make a camera that has an orthographic vertical axis, but a perspective on the horzontal axis? 1 Answer
Draw orthographic visuals (e.g. health bar) in perspective scene? 4 Answers
Rendering a 3D object within a specific area/bound? 1 Answer