-
Unity Oculus VR 물건 던지는 속도(세기) 조절하기개발/Unity 2020. 2. 13. 15:18
Oculus Intergration의 OVRGrabber 클래스는 기본적으로 OVRGrabbable 속성의 물건을 던질 수 있는데 OVRGrabber 클래스의 GrabEnd() 함수에서 잡고 있던 오브젝트를 놓을 때 마다 오브젝트의 속도를 다시 계산하기 때문이다.
하지만 오브젝트의 속도는 컨트롤러의 이동 속도를 그대로 받아오므로 오브젝트를 빠르게, 멀리 날아가게 하는 데 한계가 있다. 컨트롤러의 버튼을 사용할 수도 있지만 그러면 던지기가 아니라 발사에 가까워진다.
물체를 던지는 부분을 담당하는 OVRGrabber.cs의 함수이다.
protected void GrabEnd() { if (m_grabbedObj != null) { OVRPose localPose = new OVRPose { position = OVRInput.GetLocalControllerPosition(m_controller), orientation = OVRInput.GetLocalControllerRotation(m_controller) }; OVRPose offsetPose = new OVRPose { position = m_anchorOffsetPosition, orientation = m_anchorOffsetRotation }; localPose = localPose * offsetPose; OVRPose trackingSpace = transform.ToOVRPose() * localPose.Inverse(); Vector3 linearVelocity = trackingSpace.orientation * OVRInput.GetLocalControllerVelocity(m_controller); Vector3 angularVelocity = trackingSpace.orientation * OVRInput.GetLocalControllerAngularVelocity(m_controller); GrabbableRelease(linearVelocity, angularVelocity); } // Re-enable grab volumes to allow overlap events GrabVolumeEnable(true); } protected void GrabbableRelease(Vector3 linearVelocity, Vector3 angularVelocity) { m_grabbedObj.GrabEnd(linearVelocity, angularVelocity); if(m_parentHeldObject) m_grabbedObj.transform.parent = null; m_grabbedObj = null; }
10, 11줄에서 컨트롤러의 linearVelocity와 AngularVelocity를 받아와, GrabbableRelease의 인자로 넘겨주고, 다시 m.grabbabeObj.GrabEnd()를 호출해 잡고 있던 물체의 속도를 지정하고 있다. 따라서 이 함수의 인자를 수정하면 오브젝트를 던지는 속도를 조절해서 더 빠르게 날아가도록 할 수 있다.
GrabbableRelease(linearVelocity * 2, angularVelocity);
간단히 linearVelocity를 변경하면 오브젝트가 날아가는 속도를 바꿀 수 있으므로, 플레이어의 능력치나 상황에 따라 다양하게 응용할 수 있다.
'개발 > Unity' 카테고리의 다른 글
Unity Oculus 카메라(시점) 움직이기 (0) 2020.02.13 Unity Oculus 컨트롤러로 OVRGrabbable 오브젝트 발사하기 (0) 2020.02.06 Unity Oculus Quest 최적화 (0) 2020.02.05 Unity 충돌 감지 시 효과음 재생 (0) 2020.01.31 Unity 라이트 프로브와 실시간 조명 (0) 2020.01.31