Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commit8d45df8664

README.md

SphereCollider (component)

A spherical collision shape. Works with or without a Physics component: on its own it is static collision geometry, and alongside one it moves with the body.

Sizing

radius is in the entity's local space, multiplied by the entity's world scale. Leave it unset and the sphere derives from the entity's model bounds, and follows the mesh when renderer.mesh.setVertices or renderer.mesh.update changes it: by the next physics step the sphere takes the new geometry's size and centre.

entity.find("ball").component.add("SphereCollider", { radius = 0.5 })
entity.find("zone").component.add("SphereCollider", { radius = 5, isTrigger = true })

Fields

FieldMeaning
radiusSphere radius. Unset derives from model bounds.
isTriggerReport overlaps without blocking.
frictionSurface friction.
restitutionBounciness.
rollingResistanceHow strongly the surface resists a body rolling on it: a rolling body slows at this many times gravity on level ground, so a ball rolled at v stops after v^2 / (2 * rollingResistance * 9.81). 0 rolls on.
spinningResistanceThe same for a body spinning on the surface about the contact normal. 0 spins on.
surfaceThe surface the collider is made of, by name: one Physics.defineSurface defined gives it its friction, restitution and resistances in place of the fields above, and contacts, contact events and ray and shape casts report the name either way. Empty names none.
oneWayThe direction, in the collider's own frame, bodies pass through it along: a body moving that way goes through, and a body meeting it from the side the direction points to stands on it (a jump-through platform is {0, 1, 0}). Physics.passThrough(entity) drops a standing body through. Unset blocks from every side.
surfaceVelocityThe velocity, m/s in the collider's own frame, its surface moves at along itself while the collider stays put: friction carries what rests on it (a conveyor belt, a treadmill, an escalator). Write it at runtime to change the speed or direction. Unset holds the surface still.
contactTagThe tag the world's contact filter reads this collider by: Physics.setContactFilter(tagA, tagB, mode) makes two tags pass through each other ("ignore"), report contacts and push nothing ("sensor") or collide ("solid"). Empty names none.

Composing

A collider on a child entity attaches to the nearest ancestor carrying a Physics component. A character is a CapsuleCollider for the body and a SphereCollider trigger on a head entity; queries report whichever shape they hit, so the head stays distinguishable from the torso.