Hey guys,
I have a game with a Canvas and a play button. When the play button is pressed, I want the camera to slowly move over to focus on the player character.
I’m running into an issue where whenever I click the play button, the camera is only moving incrementally, as opposed to moving fluidly in one sweeping motion like I’d envisioned. How would I fix this?
Please find my camera move script below, any help is much appreciated
using UnityEngine;
public class MoveCamera : MonoBehaviour
{
public Transform CameraPos;
public float speed;
public void MoveCam()
{
Debug.Log("cam move");
transform.position = Vector3.MoveTowards(transform.position, CameraPos.position, speed * Time.deltaTime);
}
}
Create a Cinemachine Camera, set it to follow your character (see manual). Zero code, and you get all the AAA quality goodies like damping (smoothing), safe zones, etc.
In your code you would have to call MoveCam() from Update() for it to provide a smooth motion rather than just stepping a bit closer.