Hi all.
I have the following setup.
Whenever the player moves I calculate the x and z distance from the camera and if > xDistance/zDistance Lerp to the center.
The problem is when I rotate the camera with the right stick (no code below) with the player still in view the distances because of the change in rotation are off. The camera will still be on the player but the xDistance is no longer starting at zero from the center.
No problem when not rotating the camera because the distances are then linear.
Thanks for any assist.
Vector3 follow = new Vector3(followXForm.position.x, followXForm.position.y, followXForm.position.z);
Vector3 offset = new Vector3(0, yDistance, -zDistance);
//Vector3 target = follow + rotationAdd * offset;
Vector3 target = follow + offset;
float xD = Mathf.Abs(transform.position.x - target.x);
float zD = Mathf.Abs(transform.position.z - target.z);
//xD = 1000f;
//float smooth = (Mathf.Log(xD) * smooth2D); // lower the smooth number faster the cam follows
if (xD >= xOffset && Math.Abs(inputController.leftStickX) > 0)
{
Debug.Log("xD " + xD);
float smooth = 0;
if (xD > 0) smooth = smoothMovement / Mathf.Log(xD); // lower the smooth number faster the cam follows
//float smooth = smooth2D; // lower the smooth number faster the cam follows
Vector3 ps = new Vector3(target.x, target.y, target.z);
transform.position = Vector3.Slerp(transform.position, ps, Time.deltaTime * smooth);
//transform.position = ps;
//transform.forward = transform.TransformDirection(Vector3.forward);//forward of camera to forward of world
}
if (zD >= zOffset && Math.Abs(inputController.leftStickY) > 0)
{
float smooth = 0;
if (zD > 0) smooth = smoothMovement / Mathf.Log(zD); // lower the smooth number faster the cam follows
//float smooth = smooth2D; // lower the smooth number faster the cam follows
Vector3 ps = new Vector3(target.x, target.y, target.z);
transform.position = Vector3.Slerp(transform.position, ps, Time.deltaTime * smooth);
//transform.position = ps;
}