- Home /
Move Camera is an order so that the background doesn't move fast
I have created a game where I am moving my player on a platform. The car moves fine on the platform and the camera follows the car as well. My problem is that I wanted my background to move slowly. I am using a perspective camera and I am moving camera away to create a zoom out effect when my player jumps. Do you suggest I should move my background towards right so that it creates a simple slow effect? As currently it moves very fast.
here is my video demonstration : https://www.youtube.com/watch?v=xO_mEXo6mNA
Answer by INvalidSauce · Jan 03, 2018 at 12:48 PM
If your background, is just a gameobject that is actually in the scene, you could just move it further away from the camera, and scale it up. It's a simple perspective change. The further away something is, the less paralax movement it presents when the camera moves.
I have tried it and I came to know that moving away and scaling actually cancel out each other's effect. Let say size of $$anonymous$$e was 6 , It was at 20 units away from camera I increased size and now it's 12, I move it at 40 units. It will essentially look the same ? Isn't it ???
It will not work, if your camera is orthographic, as that removes perspective. Your camera must be a perspective camera, which you wrote it was. If it is, it will work.
Still it would better to use parallax scrolling
Answer by leSamo · Jan 03, 2018 at 10:57 AM
I don't know how your camera script works, but if you want smooth motion use:
// SupposedCameraPositionVector is a Vector3 which is where the camera is supposed to be in a new frame according to your current calculations
// modifier is a float, which decides how swiftly you want your camera to follow your car (I'd recommend setting it to something like 30f, but you can fiddle about with it and see what works for you)
private void Update() {
Vector3.Lerp(Camera.transform.position, SupposedCameraPositionVector, Time.deltaTime * modifier);
}
If you don't know what Vector3.Lerp does then go here: https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html
I have tried Lerp but the issue is that I just can't make my background move slow.
Answer by OneCept-Games · Jan 03, 2018 at 10:56 AM
In 2D scrolling games often Parallax scrolling is used. The main point is to keep all backgrounds in same Z coordinate in layers and move them with a factor between 0 and 1 according to the Camera in the opposite direction (x,y).