Unity
[Unity]카메라 360 회전 시, 부드럽게(관성)회전 방법
기억해조
2023. 9. 20. 15:08
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectRotation : MonoBehaviour
{
public float rotationSpeed = 15;//회전속도
public float smoothness = 5;//관성 값
private Quaternion targetRotation = Quaternion.identity;
void Update()
{
//회전
if (Input.GetMouseButton(0))
{
Quaternion rot = transform.rotation;
rot *= Quaternion.Euler(new Vector3(Input.GetAxis("Mouse Y") * rotationSpeed, -Input.GetAxis("Mouse X") * rotationSpeed, 0));
float x = rot.eulerAngles.x;
float y = rot.eulerAngles.y;
targetRotation = Quaternion.Euler(x, y, 0);
}
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime * smoothness);
}
}