UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"create a third person orbit camera that orbits the player based on mouse input"
using System.Collections; using System.Collections.Generic; using UnityEngine; public class ThirdPersonOrbitCam : MonoBehaviour { public Transform player; public Vector3 offset; public float zoomSpeed = 4f; public float minZoom = 5f; public float maxZoom = 15f; public float pitch = 2f; public float yawSpeed = 100f; private float currentZoom = 10f; private float currentYaw = 0f; void Update () { currentZoom -= Input.GetAxis("Mouse ScrollWheel") * zoomSpeed; currentZoom = Mathf.Clamp(currentZoom, minZoom, maxZoom); currentYaw -= Input.GetAxis("Mouse X") * yawSpeed * Time.deltaTime; } void LateUpdate () { transform.position = player.position - offset * currentZoom; transform.LookAt(player.position + Vector3.up * pitch); transform.RotateAround(player.position, Vector3.up, currentYaw); } }