World:collide
EditAttempt to collide two shapes. Internally this sets up constraint forces to move the shapes' colliders apart if they are touching. The colliders won't actually move until World:update
is called again to advance the physics simulation.
Collision responses can be customized using friction and restitution (bounciness) parameters, and default to using a mix between the parameters of the two colliders.
Usually this is called internally by World:update
, or in a custom collision resolver passed to World:update
.
If you want to detect if objects are touching without colliding them, use World:getContacts
or make one or both of the shapes sensors using Shape:setSensor
.
collided = World:collide(shapeA, shapeB, friction, restitution)
Arguments
Name | Type | Default | Description |
shapeA | Shape | The first shape. | |
shapeB | Shape | The second shape. | |
friction | number | nil | The friction parameter for the collision. |
restitution | number | nil | The restitution (bounciness) parameter for the collision. |
Returns
Name | Type | Description |
collided | boolean | Whether the shapes collided. |
Notes
For friction, numbers in the range of 0-1 are common, but larger numbers can also be used.
For restitution, numbers in the range 0-1 should be used.
This function respects collision tags, so using World:disableCollisionBetween
and World:enableCollisionBetween
will change the behavior of this function.