-
Unity/Oculus DistanceGrabber 물건 집어오는 동안 충돌 무시하게 하기개발/Unity 2020. 1. 17. 13:21
DistanceGrabber.cs 의 MoveGrabbedObject 함수를 수정
protected override void MoveGrabbedObject(Vector3 pos, Quaternion rot, bool forceTeleport = false) { if (m_grabbedObj == null) { return; } Collider[] grabbedColliders = m_grabbedObj.gameObject.GetComponentsInChildren<Collider>(); Rigidbody grabbedRigidbody = m_grabbedObj.grabbedRigidbody; Vector3 grabbablePosition = pos + rot * m_grabbedObjectPosOff; Quaternion grabbableRotation = rot * m_grabbedObjectRotOff; if (m_movingObjectToHand) { foreach(Collider col in grabbedColliders) col.isTrigger = true; float travel = m_objectPullVelocity * Time.deltaTime; Vector3 dir = grabbablePosition - m_grabbedObj.transform.position; if(travel * travel * 1.1f > dir.sqrMagnitude) { m_movingObjectToHand = false; } else { dir.Normalize(); grabbablePosition = m_grabbedObj.transform.position + dir * travel; grabbableRotation = Quaternion.RotateTowards(m_grabbedObj.transform.rotation, grabbableRotation, m_objectPullMaxRotationRate * Time.deltaTime); } } else { foreach (Collider col in grabbedColliders) col.isTrigger = false; } grabbedRigidbody.MovePosition(grabbablePosition); grabbedRigidbody.MoveRotation(grabbableRotation); }
grabbedColliders 배열에 집은 물체의 Collider들을 추가 후 가져오는 동안(m_movingObjectToHand == true)
isTrigger 속성을 true로 설정한다.
별로 좋은 방법은 아니고 꼭 필요한 처리도 아니지만 도움이 되었으니 기록.
'개발 > Unity' 카테고리의 다른 글
Unity Oculus Quest 최적화 (0) 2020.02.05 Unity 충돌 감지 시 효과음 재생 (0) 2020.01.31 Unity 라이트 프로브와 실시간 조명 (0) 2020.01.31 Unity SerializedObject target has been destroyed 오류 해결 (0) 2020.01.23 Unity Oculus 컨트롤러 진동 (0) 2020.01.21