Log inGet started
Package

Holdable.component

Newest version

This package holds more than this page lists. See all of its files in its world.

README.md

Holdable

Marks a prop as something an avatar can pick up, carry, put down, throw and pass to another avatar: a log, a pebble, a ball, a lantern, a cup, a fish a cat carries in its mouth. The game decides which props are holdable by putting Holdable on them; the Carrier component on the player's body picks them up from the player's controls, and @builtin::modules.carry does the same from code.

Public fields: grip, gripPosition, gripRotation, holder (written by holding).

Methods: :holdBy(holder), :release(opts?), :heldBy(), :gripVelocity().

log.component.add("Holdable", {})                                     -- in the right hand
lantern.component.add("Holdable", { gripPosition = { 0, -0.2, 0 } })   -- hanging below the fist
crate.component.add("Holdable", { grip = "bodyFront", gripPosition = { 0, 0, 0.3 } })
fish.component.add("Holdable", { grip = "mouth" })                     -- a cat body with a `mouth` entity

Where it is held

grip names the grip point:

  • on a humanoid avatar, an attachment point (rightGrip and leftGrip are the palms, bodyFront carries a large object before the chest, faceFront stands before the face at eye level, and a gripPosition lowered a few centimetres holds one in the mouth), a role or a bone name, resolved by Humanoid:attach, so the same numbers seat it the same way on every conforming body;
  • on any other body, the name of an entity under it (mouth, frontPaw).

gripPosition (metres) and gripRotation (Euler degrees: x pitch, y yaw, z roll) place it in that point's frame: +Y up, +Z forward and +X the body's left as the body stands in a T-pose. It keeps its size.

Held and let go

:holdBy(holder) seats it on the grip: it becomes a child of the grip, so it rides the body's animation, its Physics turns kinematic (it pushes what it is swung into), it passes through its holder (Physics.ignoreCollision), and holder names the avatar on every peer. A prop held by one avatar of this peer moves straight to the next.

:release(opts) lets go. It goes back under the entity it stood under, takes its Physics kind again and passes through the avatar that let it go for a moment:

optsWhat happens
noneIt falls from the hand, moving as the grip moved (:gripVelocity()).
velocityA throw: that velocity (m/s, world) added to the grip's.
position, rotationPut down there.
stillLet go at rest.
inPlaceOff the grip and held where it stands, still kinematic, for another avatar's grip to take; a prop no grip takes within the hand-over time falls loose.

Across peers

The peer that holds a prop owns it. :holdBy runs on the prop's owner; carry.pickUp and Carrier:pickUp take ownership first, asking the peer that owns it, which hands it over when nobody holds it. While held, its pose travels in its holder's space (multiplayer.setPoseFrame): every peer draws it where the holder's peer holds it against the holder's body, so it moves with the body on every screen. A peer that takes a held prop over from a peer that left lets it fall.