Unity에서 충돌을 묘사하기 위해서는 Collider 컴포넌트를 사용해야 한다. 충돌을 나타내는 함수에는 Collision과 Trigger가 있다. 둘다 collider가 충돌했을 때 사용하는 함수이지만 다른 특징이 있다.
OnCollisionEnter의 경우, 충돌의 물리 연산이 이루어지며 서로 관통하지 않는다.
Collision을 사용하기 위해서는
1. 나 혹은 상대에게 RigidBody가 있어야 한다. (IsKinematic은 꺼져있는 상태)
2. 나와 상대에게 Collider가 있어야 한다. (IsTrigger은 꺼져있는 상태)
OnTriggerEnter의 충돌은 물리 연산 없이 이루어지고 서로 관통한다.
Trigger를 사용하기 위해서는
1. 둘 다 Collider가 있어야 한다.
2. 둘 중 하나는 IsTrigger가 켜져있어야 한다.
3. 둘 중 하나는 RigidBody가 있어야 한다.
아래 사이트에 매우 친절하고 자세한 내용으로 담겨져 있다.
https://levelup.gitconnected.com/oncollisionenter-vs-ontriggerenter-when-to-use-them-56d42772dd22
OnCollisionEnter vs. OnTriggerEnter — When to use them
Colliders are added to GameObjects to reflect their physical structure and to simulated real-world physics.
levelup.gitconnected.com
https://docs.unity3d.com/Manual/CollidersOverview.html
Unity - Manual: Introduction to collision
Continuous collision detection (CCD) Introduction to collision Unity handles collision between GameObjects with colliders, which attach to GameObjects and define the shape of a GameObjectThe fundamental object in Unity scenes, which can represent character
docs.unity3d.com
'공부 > Unity' 카테고리의 다른 글
[Unity] Debug 디버깅과 오류 해결하기 (0) | 2022.05.02 |
---|---|
[Unity] UseGravity, IsKinematic, IsTrigger 실습 (0) | 2022.05.02 |
[Unity] 오일러 각(eulerAngles)과 쿼터니언(quaternion) (0) | 2022.05.02 |
[Unity] NullReferenceException (0) | 2022.05.02 |
[Unity] testrunner.dll does not exist - 2 (0) | 2022.05.02 |