I am working on a 3D Camera controller, where player is able to rotate the camera around an object using mouse. transform.RotateAround()
is perfect for this, except for one thing - I can't figure out a way to smoothly lerp it.
For reference - this is old code, which made camera rotate smoothly, but without a specific Target, just around an arbitrary point:
private void Rotate(){
if(!EnableRotation || RotationTarget == null) return;
if(Input.GetKeyDown(KeyCode.R)) _newRotation = Quaternion.identity;
if(Input.GetKey(KeyCode.Mouse1)){
float xInput = Input.GetAxis("Mouse X");
_newRotation *= Quaternion.Euler(Vector3.up * RotationSpeed * xInput * RotationSensitivity);
}
}
private void UpdateRotation(){
transform.rotation = Quaternion.Lerp(transform.rotation,_newRotation,Time.deltaTime * RotationDampening);
}
And this, is what I have currently:
private void Rotate(){
if(!EnableRotation || RotationTarget == null) return;
if(Input.GetKeyDown(KeyCode.R)) _newRotation = Quaternion.identity;
if(Input.GetKey(KeyCode.Mouse1)){
float xInput = Input.GetAxis("Mouse X");
transform.RotateAround(RotationTarget.position,Vector3.up,RotationSpeed * xInput);
}
}
So my big question is - is there a way to lerp the rotation of transform.RotateAround()
? Make it smooth. Or are there any other ways of doing this?
Thanks in advance.
I feel like I've tried everything, but no success so far.