DistanceGrabbable to a transform entity after enabling the grabbing feature.import {
DistanceGrabbable,
MovementMode,
RayInteractable,
World,
} from '@iwsdk/core';
const world = await World.create(container, {
features: { grabbing: true },
});
const entity = world.createTransformEntity(mesh);
entity.addComponent(RayInteractable);
entity.addComponent(DistanceGrabbable, {
movementMode: MovementMode.MoveTowardsTarget,
moveSpeedFactor: 0.1,
targetPositionOffset: [0, 0, -0.3],
targetQuaternionOffset: [0, 0, 0, 1],
});
MovementMode has four values:| Value | Behavior |
|---|---|
MoveTowardsTarget | Interpolates position and orientation toward an offset from the input source. |
MoveAtSource | Applies the input source’s position delta while preserving the object’s distance. |
MoveFromTarget | Delegates movement to the standard projected-ray handle. |
RotateAtSource | Rotates in place and disables translation and scale for the handle. |
targetPositionOffset by the pointer orientation and adds it to the pointer origin.targetQuaternionOffset.0.005 world units.moveSpeedFactor, frame delta, and the handle’s internal scale. It is not a fixed distance per frame.moveSpeedFactor in the initial addComponent() data, as shown in the
first example. GrabSystem copies it into the handle when the component is
initialized, so changing the component field later does not reconfigure the
existing handle. The value defaults to 0.1 and uses a scale from 0 to 1.entity.addComponent(DistanceGrabbable, {
movementMode: MovementMode.MoveFromTarget,
rotate: true,
translate: true,
scale: false,
translateMin: [-2, 0, -2],
translateMax: [2, 3, 2],
});
returnToOrigin to restore the position, orientation, and scale captured when each grab starts.entity.addComponent(DistanceGrabbable, {
movementMode: MovementMode.MoveAtSource,
returnToOrigin: true,
});
detachOnGrab: true attaches the target to the scene or level root when grabbing begins. Use it when a parent transform must not continue to affect the manipulated object.