UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"create a 3rd person orbit camera controller that uses mouse input to orbit the player"
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ThirdPersonOrbitCam : MonoBehaviour { public Transform player; // the object being followed public Vector3 offset; // offset from the target object [SerializeField] private float rotateSpeed = 5; // speed of camera rotation private float rotateY; // Start is called before the first frame update void Start() { offset = player.position - transform.position; // maintain initial offset } // Update is called once per frame void LateUpdate() { float horInput = Input.GetAxis("Mouse X"); rotateY += horInput * rotateSpeed; // offset = Quaternion.AngleAxis(rotateY, Vector3.up) * offset; transform.position = player.position - offset; transform.LookAt(player); } }