Skip to content

Commit

Permalink
add info about collection proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
AGulev committed Apr 6, 2024
1 parent 8065f21 commit 33bc41f
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions docs/en/manuals/physics-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,26 @@ Previously, physics interactions in Defold were handled by broadcasting messages

## Setting the Physics World Listener

To start using this new functionality, you need to use the `physics.set_listener` function. This function takes a callback as its argument, which will be called with information about all physics interactions in the world. The general syntax is as follows:
In Defold, each collection proxy creates its own separate physics world. Therefore, when you are working with multiple collection proxies, it's essential to manage the distinct physics worlds associated with each. To ensure that physics events are handled correctly in each world, you must set a physics world listener specifically for each collection proxy's world.

```lua
physics.set_listener(function(self, event, data)
-- Event handling logic goes here
end)
This setup means that the listener for physics events must be set from within the context of the collection that the proxy represents. By doing so, you associate the listener directly with the relevant physics world, enabling it to process physics events accurately.

Here is an example of how to set a physics world listener within a collection proxy:

```lua
function init(self)
-- Assuming this script is attached to a game object within the collection loaded by the proxy
-- Set the physics world listener for the physics world of this collection proxy
physics.set_listener(physics_world_listener)
end
```

By implementing this method, you ensure that each physics world generated by a collection proxy has its dedicated listener. This is crucial for handling physics events effectively in projects that utilize multiple collection proxies.

---

This update should make it clear that each collection proxy creates a new physics world and that listeners must be set within each respective collection proxy to manage physics events properly.

::: important
If a listener is set, [physics messages](/manuals/physics-messages) will no longer be sent.
:::
Expand Down

0 comments on commit 33bc41f

Please sign in to comment.