Hi guys,
I follow this Parallaxing Tutorial:
.
I created a custom Script for my GameObjects like this (EDIT: this is in the Update function):
// ---- Move in parallaxing ----
//Calculate parallax
float parallax = (previousCamPos.x - cam.transform.position.x) * (transform.position.z*-1f);
//Calculate the new X Position
float backgroundTargetPosX = transform.position.x + parallax;
//New Vector3
Vector3 backgroundTargetPos = new Vector3(backgroundTargetPosX, transform.position.y, transform.position.z);
//Lerp
transform.position = Vector3.Lerp(transform.position, backgroundTargetPos, smoothing * Time.deltaTime);
//Save Previous Cam Position
previousCamPos = cam.transform.position;
My CameraFollowScript:
public class CameraFollow : MonoBehaviour {
public Camera cam;
public Transform target;
void Update ()
{
Bounds cameraBounds = MathUtils.OrthographicBounds(cam);
float padding = cameraBounds.size.x * 30 / 100;
Vector3 newPos = new Vector3(target.transform.position.x + padding, 0, -10);
transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime);
}
}
And works perfectly.
I noticed, however, that when for example the background of my desktop changes, or try to record with quicktime, parallax slows down and moves in a very strange way.
I’m doing an endless running game, where the character runs to the right, my parallax move to left, as it should be. But when this thing happens, the parallax move quickly to the right.
How could this thing happen?
missing a Time.deltatime in the script?