What is the best way to make smooth camera movement and rotation? (with my script)

Right now the way my camera moves is by being inside of the player and following the player movement.

Player Script

    Vector3 moveHorizontal = MyCamera.transform.right * Input.GetAxisRaw("Horizontal") * speed;
    Vector3 moveVertical = MyCamera.transform.forward * Input.GetAxisRaw("Vertical") * speed;
    // rb getting the rigidbody Component
    rb.velocity = (moveHorizontal + moveVertical);

Camera Script

public Vector3 myPos; //camera position
public Transform myPlay; // player position

void Update () {
transform.position = myPlay.position + myPos;
}

I also have another method of camera rotation when certain buttons are pressed.

Camera Script

private float goodDegs = 2.0f;
private float badDegs = -2.0f;

Void Update () {
if (Input.GetKey (KeyCode.E)) {
			for (float i = 0; i < 90; i++) {
				transform.Rotate (0, goodDegs * Time.deltaTime, 0);
			}
		}

		if (Input.GetKey (KeyCode.Q)) {
			for (float m = 0; m < 90; m++) {
				transform.Rotate (0, badDegs * Time.deltaTime, 0);
			}
		}
}

What I want to do is turn it into a smooth rotation rather than just quickly jumping to new positions, I’ve looked elsewhere, but am not too sure what to use.

I am no expert, most of what I’ve done has been with help from forum answers.

1 Answer

1

Instead of applying hard rotation, use slerp or lerp to smooth it out.
Difference between them is perfectly showcased in this video, where lerp is the linear line.