Log inGet started
World

Builtin Library

Branchmain
Branchesmainpublish
Commitf04f1df392

README.md

Carrier

Lets an avatar pick up, carry, put down and throw the props a game marks Holdable, from the player's controls: the same on keyboard and mouse, gamepad and touch. Put it on the player's body (the body of a PlayerPrototype) or on any avatar a script drives.

Public fields: inputMap, control, throwControl, reach, throwSpeed, minThrowSpeed, chargeSeconds, tapSeconds, throwAngle, acceptGifts, giveReach.

Methods: :pickUp(prop?), :drop(), :place(position, rotation?), :throw(speed?), :give(receiver), :receiver(), :held(), :aim(), :windUp().

-- in a scene's build.luau: the player's body picks up and throws
body.component.add("Carrier", {})

-- a separate throw control
body.component.add("Carrier", { throwControl = "jump", throwSpeed = 12 })

-- from code
local hands = player.avatar.component.get("Carrier")
hands:pickUp()                 -- the nearest loose holdable prop in front
hands:throw()                  -- at throwSpeed where the camera looks
hands:give(friend.avatar)      -- into another player's hand

The controls

One control does all of it: control, interact on the default map (E, the pad's west button, the on-screen Interact button).

  • Pressed with empty hands, it picks up the nearest loose holdable prop in front of the avatar (the way its body visibly faces) within reach metres of the point just before it at waist height.
  • Pressed while holding, a tap shorter than tapSeconds hands the prop to another player: the nearest avatar carrying a Carrier, with empty hands, that stands in front within giveReach metres (2.5) takes it into its hand. With nobody there, the tap puts the prop down: it falls from the hand. :receiver() names the avatar a tap hands to right now, for a prompt such as "Give to Ana".
  • Held longer, it winds up a throw that leaves on release, from minThrowSpeed up to throwSpeed after chargeSeconds (:windUp() reads how far).

Name a throwControl on the map and that control throws (winding up the same way) while control picks up, hands over and puts down.

The controls are taken on the peer that drives the avatar (isLocal()), so another player's body answers to nothing here.

Throwing

A throw leaves where the player's camera looks, lifted by throwAngle degrees (:aim(); an avatar with no camera of this peer's uses its own facing), and carries the hand's own velocity, so a throw on the run goes further. The prop takes its physics again and settles where it lands; a prop with FluidForces floats in water (Water) or sinks by its density.

Passing

A tap of the control hands the prop held to the player standing in front (above). From code, :give(receiver) hands it to any other avatar: straight into its grip when this peer drives both, and otherwise offered to the receiver's peer, which takes it when the receiver's acceptGifts is on. @builtin::modules.carry has the whole capability for code (carry.pickUp, carry.drop, carry.place, carry.throw, carry.give, carry.nearestReceiver, carry.heldBy, carry.holderOf, carry.nearest, carry.gripOf).