World:collide

Edit

Attempt 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

NameTypeDefaultDescription
shapeAShape The first shape.
shapeBShape The second shape.
frictionnumbernil The friction parameter for the collision.
restitutionnumbernil The restitution (bounciness) parameter for the collision.

Returns

NameTypeDescription
collidedboolean 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.

See also