Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commite8beb5604c

README.md

sim.collider (procNode)

A shape particles cannot enter, a plane, a sphere or a box, for a solver such as sim.particles. A particle reaching it is pushed back to its surface and bounces off it. Wire any number of them, with sim.scene_colliders, into sim.particles' colliders.

Inputs

  • shape (String, default "plane"): "plane", "sphere" or "box". A plane makes everything below a surface through center facing normal solid; a sphere is a ball of radius; a box is an axis-aligned box of size.
  • center (Vec3, default (0, 0, 0)): a point on the plane, or the middle of the sphere or box.
  • normal (Vec3, default (0, 1, 0)): which way a plane faces: the side it points to is open, the other solid. Normalized on use. Read for a plane.
  • radius (Float, default 1, min 0): the sphere's radius. Read for a sphere.
  • size (Vec3, default (1, 1, 1)): the box's full size along each axis. Read for a box.
  • bounce (Float, default 0.5, 0 to 1): the share of its speed into the surface a particle keeps, turned back out.
  • friction (Float, default 0.1, 0 to 1): the share of its speed along the surface a particle loses on contact.

Outputs

  • collider (Record): the shape as a solver reads it. kind is "sim.collider"; shapes is the one-row shape table the solver joins with the others, a Points geometry whose point carries shapeKind (0 plane, 1 sphere, 2 box), center, extent (a plane's unit normal, a sphere's radius in x, a box's half size), rotation (the identity quaternion), bounce and friction; shape, normal, radius, half, shapeKind, center, extent, rotation, bounce and friction are the same values as fields of the record. bounce and friction are clamped to 0..1.

Example

local source = g.sim.spawn({ points = g.points.grid({ countX = 1, countZ = 1, y = 1 }), rate = 60 })
local floor = g.sim.collider({ shape = "plane", center = vector.create(0, 0, 0), bounce = 0.3 })
local sim = g.sim.particles({ sources = { source }, colliders = { floor }, gravity = vector.create(0, -9.8, 0) })