I want to sample one point inside the collision shape.
I searched the api document, but there is no way to find the position of the collision shape relative to a game object.
Is there any way to sample one random point inside the collision shape?
For example: Random Sampling
Box2D has a test_point() function which probably is what you’re after, but this is not part of the Defold API.
A workaround might be using a trigger collision object:
- Create a game object containing a 1x1 pixel trigger with a default position outside the collision object.
- Move the trigger game object to the point you’d like to check.
- Wait for a trigger collision message with enter, indicating it’s inside the collision shape
Another workaround could be using the native Box2D extension or a Lua library like Bump or Hardon collider, all of which can check collisions against a point.
Thank you! I will try the methods you suggest!
1 Like