Skip to content

Grabbing

oneMillionWorlds edited this page Dec 15, 2025 · 9 revisions

Grabbing is supported when hands are bound, starting with an already bound hand grabbing can be activated as follows

FunctionRegistration functionRegistration = boundHand.setGrabAction(ActionConstants.GRIP_STRENGTH, node);

(ActionConstants.GRIP_STRENGTH being a constant previously declared in user code and registered in the action manifest)

This takes the name of the action that controls grabbing (should be set in the action manifest) and a node that has things that has grabbable things attached to it (in a simple example this may be the root node). When the action is to be removed (e.g. you've exited the level to the main menu) functionRegistration.endFunction() will end the function.

Once this is done the hand will automatically respond to grab events. When the grab action is triggered geometry picking will be used to find objects near the palm of the hand (specific pick points and distances can be configured via methods on the bound hands)

grab points on hand

Red line indicates the origin of the palm, the red and pink lines show the lines scanned for geometries for grabbing.

Grab support

If a spatial has a control of type AbstractGrabControl that control will be informed when a hand grabs it. Tamarin provided grab controls include:

  • SnapToHandGrabControl will move geometries based on being grabbed, on grab the item is "snapped" to a configured position. Good if the object should always be held a certain way
  • RelativeMovingGrabControl Like SnapToHandGrabControl will move geometries based on being grabbed, but does not "snap" them to a particular orientation in the hand. Good for large things that you might be moving around with the hand but don't have natural "handles"
  • ParentRelativeMovingGrabControl Accepts grabs on the object the control is attached to but actually moved the node passed to the control. Used for things like handles where the handle has the control attached to it can accepts grabs but the whole object actually moves (like RelativeMovingGrabControl does not "snap" to a position
  • GrabEventControl A simple function callback on grab
  • ClimbingPointGrabControl A point that when grabbed will lead to the player moving, rather than the grabbed object

Restricted path grab support

With GrabControls that extend AbstractRelativeMovingGrabControl it is possible to restrict the motion of the spatials to a path (Can be any user defined path or volume). This could be useful for a physical slider control, where you can grab and slide it but it will only move along its slide path.

RelativeMovingGrabControl relativeGrabControl = new RelativeMovingGrabControl();
relativeGrabControl.setGrabMoveRestriction(new RestrictToLocalLine(minPosition, maxPosition));

The path can be relative to the parent of the spatial with the GrabControl; this means you can chain multiple slideable pieces. Or it can be global

An example of this can be seen in the RestrictedLineGrabMovement example

image

Snap to points

It is also possible to make spatials snap to points when the hand moves them close (for example gear positions on a manual gear stick)

    RelativeMovingGrabControl grabControl = new RelativeMovingGrabControl();
    grabControl.setSnapToPoints(new SnapToConfiguration(List.of(
            new SnapToLocalPoint(first, snapToDistance),
            new SnapToLocalPoint(second, snapToDistance),
            new SnapToLocalPoint(third, snapToDistance),
            new SnapToLocalPoint(fourth, snapToDistance),
            new SnapToLocalPoint(fifth, snapToDistance),
            new SnapToLocalPoint(sixth, snapToDistance)),
            snapChangeCallback
            ));

image

Clone this wiki locally