So im making a little 2D platformer to get the hang of unity. I have a character and a camera that follows the player in a 2d plane. What I think would be cool is if the camera also rotated to smooth out the motion, leaving a way for me to have some small 3D elements in the scene. I couldnt find any answers online so I thought I would try here. Heres the code I have so far for the camera movement:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Camera_controller : MonoBehaviour
{
public GameObject player;
private float smoothTime = 0.25f;
private Vector3 velocity = Vector3.zero;
private Vector3 offset = new Vector3(0f, 0f, -10f);
[SerializeField] private Transform target;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Vector3 targetPosition = target.position + offset;
transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
}
}
again, the movement is nice and smooth now, but I would also like the camera to rotate to follow the player along with the x&y axis movement. Thanks!