|
@@ -22,6 +22,16 @@ The `"collision_response"` message is sent for all collision objects. It has the
|
|
|
|
|
|
The collision_response message is only adequate to resolve collisions where you don't need any details on the actual intersection of the objects, for example if you want to detect if a bullet hits an enemy. There is only one of these messages sent for any colliding pair of objects each frame.
|
|
|
|
|
|
+```Lua
|
|
|
+function on_message(self, message_id, message, sender)
|
|
|
+ -- check for the message
|
|
|
+ if message_id == hash("collision_response") then
|
|
|
+ -- take action
|
|
|
+ print("I collided with", message.other_id)
|
|
|
+ end
|
|
|
+end
|
|
|
+```
|
|
|
+
|
|
|
## Contact point response
|
|
|
|
|
|
The `"contact_point_response"` message is sent when one of the colliding objects is dynamic or kinematic. It has the following fields set:
|
|
@@ -61,6 +71,18 @@ The `"contact_point_response"` message is sent when one of the colliding objects
|
|
|
|
|
|
For a game or application where you need to separate objects perfectly, the `"contact_point_response"` message gives you all information you need. However, note that for any given collision pair, several `"contact_point_response"` messages can be received each frame, depending on the nature of the collision. See [Resolving collisions for more information](/manuals/physics-resolving-collisions).
|
|
|
|
|
|
+```Lua
|
|
|
+function on_message(self, message_id, message, sender)
|
|
|
+ -- check for the message
|
|
|
+ if message_id == hash("contact_point_response") then
|
|
|
+ -- take action
|
|
|
+ if message.other_mass > 10 then
|
|
|
+ print("I collided with something weighing more than 10 kilos!")
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+```
|
|
|
+
|
|
|
## Trigger response
|
|
|
|
|
|
The `"trigger_response"` message is sent when a colliding object is of type "trigger".
|
|
@@ -73,3 +95,18 @@ In a trigger collision `"collision_response"` messages are sent. In addition, tr
|
|
|
|
|
|
`enter`
|
|
|
: `true` if the interaction was an entry into the trigger, `false` if it was an exit. (`boolean`).
|
|
|
+
|
|
|
+```Lua
|
|
|
+function on_message(self, message_id, message, sender)
|
|
|
+ -- check for the message
|
|
|
+ if message_id == hash("trigger_response") then
|
|
|
+ if message.enter then
|
|
|
+ -- take action for entry
|
|
|
+ print("I am now inside", message.other_id)
|
|
|
+ else
|
|
|
+ -- take action for exit
|
|
|
+ print("I am now outside", message.other_id)
|
|
|
+ end
|
|
|
+ end
|
|
|
+end
|
|
|
+```
|