This translation is community contributed and may not be up to date. We only maintain the English version of the documentation. Read this manual in English
두 오브젝트가 충돌하면 엔진은 이벤트 콜백에 이벤트를 보내거나 두 오브젝트 모두에 메세지를 브로드캐스트합니다.
생성되는 이벤트의 타입은 각 오브젝트의 플래그로 제어할 수 있습니다:
기본적으로 이 값들은 모두 true입니다.
두 충돌 오브젝트가 상호작용할 때, 해당 체크박스 상태에 따라 사용자에게 메세지를 보내야 하는지 확인합니다.
예를 들어 “Generate Contact Events” 체크박스가 다음과 같을 때:
physics.set_event_listener()를 사용하는 경우:
| 컴포넌트 A | 컴포넌트 B | 메세지 전송 |
|---|---|---|
| ✅︎ | ✅︎ | 예 |
| ❌ | ✅︎ | 예 |
| ✅︎ | ❌ | 예 |
| ❌ | ❌ | 아니요 |
기본 메세지 핸들러를 사용하는 경우:
| 컴포넌트 A | 컴포넌트 B | 메세지 전송 |
|---|---|---|
| ✅︎ | ✅︎ | 예 (A,B) + (B,A) |
| ❌ | ✅︎ | 예 (B,A) |
| ✅︎ | ❌ | 예 (A,B) |
| ❌ | ❌ | 아니요 |
충돌하는 오브젝트 중 하나가 “dynamic”, “kinematic” 또는 “static” 타입이면 "collision_response" 메세지가 전송됩니다. 이 메세지에는 다음 필드가 설정됩니다:
other_idhash).other_positionvector3).other_grouphash).own_grouphash).collision_response 메세지는 오브젝트의 실제 교차에 대한 세부 정보가 필요 없는 충돌을 해결하는 경우에만 적합합니다. 예를 들어 총알이 적에게 맞았는지 감지하려는 경우입니다. 충돌하는 오브젝트 쌍마다 프레임당 이 메세지는 하나만 전송됩니다.
function on_message(self, message_id, message, sender)
-- 메세지 확인
if message_id == hash("collision_response") then
-- 동작 수행
print("I collided with", message.other_id)
end
end
충돌하는 오브젝트 중 하나가 “dynamic” 또는 “kinematic” 타입이고, 다른 하나가 “dynamic”, “kinematic” 또는 “static” 타입이면 "contact_point_response" 메세지가 전송됩니다. 이 메세지에는 다음 필드가 설정됩니다:
positionvector3).normalvector3).relative_velocityvector3).distancenumber).applied_impulsenumber).life_timenumber).massnumber).other_massnumber).other_idhash).other_positionvector3).other_grouphash).own_grouphash).오브젝트를 정확히 분리해야 하는 게임이나 어플리케이션에서는 "contact_point_response" 메세지가 필요한 모든 정보를 제공합니다. 그러나 주어진 충돌 쌍마다 충돌의 특성에 따라 매 프레임 여러 개의 "contact_point_response" 메세지를 받을 수 있다는 점에 유의하세요. 자세한 내용은 충돌 해결을 참고하세요.
function on_message(self, message_id, message, sender)
-- 메세지 확인
if message_id == hash("contact_point_response") then
-- 동작 수행
if message.other_mass > 10 then
print("I collided with something weighing more than 10 kilos!")
end
end
end
충돌하는 오브젝트 중 하나가 “trigger” 타입이면 "trigger_response" 메세지가 전송됩니다. 메세지는 충돌이 처음 감지될 때 한 번, 그리고 오브젝트가 더 이상 충돌하지 않을 때 한 번 더 전송됩니다. 이 메세지에는 다음 필드가 있습니다:
other_idhash).entertrue, 빠져나간 경우 false입니다(boolean).other_grouphash).own_grouphash).function on_message(self, message_id, message, sender)
-- 메세지 확인
if message_id == hash("trigger_response") then
if message.enter then
-- 진입 동작 수행
print("I am now inside", message.other_id)
else
-- 이탈 동작 수행
print("I am now outside", message.other_id)
end
end
end