0
\$\begingroup\$

If my camera does not change position but rotates, Does lerp do anything?

        cameraposition = Vector3.Lerp(Camera.main.transform.position, Camera.main.transform.position, Time.deltaTime * cameraLerp);
        Camera.main.transform.position = cameraposition;
        Camera.main.transform.LookAt(gameobject.transform.position);
\$\endgroup\$
2
\$\begingroup\$

These two lines together do nothing:

cameraposition = Vector3.Lerp(Camera.main.transform.position, Camera.main.transform.position, Time.deltaTime * cameraLerp); 
Camera.main.transform.position = cameraposition; 

Lerp is just a math function, that returns a value along the line between the first and second argument. If those two arguments are the same then it's just returning that argument, no matter what number you put in the third place (excluding NaNs and infinities as "not numbers")

So this is the same as:

a = lerp(b, b, t)
  = (1-t) * b + t * b
  = b

b = a

It does not leave any kind of residue behind that affects later operations like rotation.

If you want to smooth the rotation, you should use a Lerp or RotateTowards to compute the Quaternion orientation, not the position. eg:

Vector3 lookDirection = target.position - camera.position;
Quaternion targetOrientation = Quaternion.LookRotation(lookDirection);

camera.rotation = Quaternion.RotateTowards(
                    camera.rotation,
                    targetOrientation,
                    Time.deltaTime * degreesPerSecond
                );
| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thanks a bunch. \$\endgroup\$ – TeachMeEverything May 11 '19 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.