private void LateUpdate() { Instance = this; if (HasCamera && HasTarget) { bool buttonSafe = RPGControllerUtils.GetButtonSafe(MouseLookButton, false); realDistance -= RPGControllerUtils.GetAxisRawSafe(ZoomAxis, 0f) * ZoomSpeed; realDistance = Mathf.Clamp(realDistance, MinDistance, MaxDistance); targetDistance = realDistance; targetDistance = Mathf.Clamp(targetDistance, currentMinDistance, currentMaxDistance); currentDistance = targetDistance; Vector3 vector = new Vector3(0f, 0f, 0f - currentDistance); if (buttonSafe) { targetPitch -= RPGControllerUtils.GetAxisRawSafe(PitchAxis, 0f) * 4f; targetPitch = Mathf.Clamp(targetPitch, MinPitch, MaxPitch); } targetYaw = RPGControllerUtils.SignedAngle(vector.normalized, -Target.transform.forward, Vector3.up); targetYaw = Mathf.Repeat(targetYaw + 180f, 360f) - 180f; currentYaw = targetYaw; currentPitch = targetPitch; vector = Quaternion.Euler(currentPitch, currentYaw, 0f) * vector; base.transform.position = TargetPosition + vector; Vector3 position = base.transform.position; base.transform.position = new Vector3(position.x, Mathf.Clamp(position.y, yClamp, float.MaxValue), position.z); Camera.transform.LookAt(TargetPosition); } }
private void Start() { Instance = this; if (!HasCamera) { Camera = GetComponentInChildren <Camera>(); } if (!HasTarget) { try { Target = GameObject.FindGameObjectWithTag("CameraTarget").transform; } catch { } } MinPitch = Mathf.Clamp(MinPitch, -85f, 0f); MaxPitch = Mathf.Clamp(MaxPitch, 0f, 85f); MinDistance = Mathf.Max(0f, MinDistance); currentMinDistance = MinDistance; currentMaxDistance = MaxDistance; currentYaw = (targetYaw = 0f); currentPitch = (targetPitch = Mathf.Lerp(MinPitch, MaxPitch, 0.6f)); currentDistance = (targetDistance = (realDistance = Mathf.Lerp(MinDistance, MaxDistance, 0.5f))); }