XRShared Force Grabbing
ForcePhysicsGrabbable is the force follow of physics grabbing, in the XRShared addon: springs of limited strength pull the held object toward the hand. The physics grabbing page covers what both follows share, and the choice between them.
Overview
What users feel, and why
- Heavier or longer objects follow the hand more slowly, because the springs have the same strength whatever the object, like an arm.
- A blocked object stops, and users push harder by moving the hand further: the spring force grows with the gap between the hand and the object, and so does the vibration.
- An object hit at its far end turns in the hand before the hand is pushed back, because the wrist spring (rotation) is much softer than the arm spring (position).
- A held object does not droop, as the hand carries its weight.
- Past a limit, the object slips for a moment, then the grip recovers, as a real grip would. When the hand gets too far from the object, or yanks it, the springs weaken for a short time (a stagger). Otherwise a blocked object would be pulled harder and harder, up to
maxForce. - The ghost of the object turns red near the grip limits, to warn the holder before the object slips.
- After a teleport or a snap turn, the held object is placed on the hand at once, instead of being dragged across the room.
Setup
Follow the physics grabbing setup, with NetworkForcePhysicsGrabbable and ForcePhysicsGrabbable as the follow's components.
The DemoForceGrabbing scene uses variants of Runtime/Demo/ForceGrabbing/Prefabs/ForceGrabbable.prefab, a 1 kg cube without gravity, with a ghost and CollisionAuthorityTransfer: cube, cylinder, sphere (3 kg) and sword. The last three use gravity. The quickest start is a variant of one of them with your own visual and colliders: remove their demo parts, AuthorityVisualization (it colors the object by state authority) and the text label. The Line Drawing addon's NetworkLineDrawing Force prefab turns finished drawings into force grabbed objects.
How it works
The springs
A force adds to everything else acting on the object (contacts, gravity, the network correction), where a set velocity replaces it, and that is what lets an obstacle push the object back. At each physics step while the object is held, the arm spring pulls the grab point toward the hand with a force, and the wrist spring turns the object toward its rotation in the hand with a torque.
Each spring has a fixed stiffness, the same for every object, like an arm's strength. It is set as the frequency at which it would move a reference object (referenceMass, referenceInertia), so heavier objects follow more slowly. Its damper is fixed the same way, so a much heavier object overshoots a little when the hand stops.
The springs are PD controllers (a spring and a damper) in their stable form (Tan, Liu, Turk, 2011). The force is computed from the state the object will have after the physics step, which keeps stiff springs stable on light objects. The damper's target velocity is the hand velocity, so the object moves with the hand instead of trailing behind it. There is no integral term: in contact, the remaining gap comes from the obstacle, and an integral would push harder and harder.
The hand motion
The hand pose is sampled at each render, while the springs act at each physics step. HandMotionEstimator (public, reusable in other follows) bridges the two: it estimates a smoothed hand velocity from successive renders, and extrapolates the last hand pose to the end of the physics step. It predicts the hand, never the object, since collisions make the object's motion unpredictable. The velocity includes the rig's motion, so an object held while walking moves with the user, and a throw while walking carries the walking speed.
The gap and grip failure
Nothing stops a real hand: in VR, users can always push their hand through a virtual obstacle. Without a consequence, they would brute-force their way, shoving a sword through a shield or holding an object through a wall, with no regard for the virtual situation. The grip failure gives that a cost, as a real grip would: pushed or yanked too hard, the object slips for a moment. Users then play with the virtual world, parrying and going around obstacles, instead of against it. It is one approach to that gameplay problem, not the only one: dropping the object, slowing the displayed hand or applying damage are others, and the same gap can drive them.
The gap (a distance and an angle) is measured between the hand and the object at the same instant. It stays near zero while the object follows a fast swing, and grows when something holds the object back. It drives the grip failure and the ghost. The vibration grows with a similar distance, between the tracked hand and the displayed hand, measured by the hand's NetworkRigPart (its settings).
A tracking glitch that makes the hand jump also makes the grip fail for a moment, and fires onGripFailure. The follow does not filter out fast hand moves, as a hand speed limit would also stop real throws.
From code, read GripState (Holding, Staggered, Recovering), GripStrength and GripFailureProximity on ForcePhysicsGrabbable.
Networking
On top of the networking model of physics grabbing:
- On other clients, the spring forces add to the
NetworkTransformcorrection (see The springs). - The hand velocity estimate and the grip are local. Each client evaluates the grip from its own view of the hand and the object, so
onGripFailurefires on each client where the grip fails, not always on all of them. Apply gameplay effects (damage, score) on the state authority only. - Beyond
teleportDistance(a stuck object), only the state authority moves the object to the hand, and networks the teleport: other clients snap it instead of dragging it through walls.
Settings
The defaults are a starting point. Watch tuningReadout in the Inspector in Play mode: it shows the gap, the force and torque and whether they reach their caps, the grip state, and the effective damping ratios. Then judge the feel on a device build. The springs are set in Hz and need no conversion for another Fixed Timestep; against an obstacle, they push a little less with a longer step.
ForcePhysicsGrabbable has no centerOfMassAtGrabPoint: the center of mass always moves to the grab point, as the arm spring needs it. The release and inertia settings are on the physics grabbing page.
Springs
referenceMass and referenceInertia only set the scale of the frequencies: keep them, and tune positionFrequency and rotationFrequency.
| Field | Default | What it does |
|---|---|---|
positionFrequency |
3 Hz | Arm spring stiffness, as its frequency for an object of referenceMass. Raise it for snappier objects that push harder, lower it for a heavier feel |
rotationFrequency |
2.3 Hz | Wrist spring stiffness, as its frequency for an object of referenceInertia. Raise it for objects that should keep their orientation firmly |
positionDampingRatio, rotationDampingRatio |
1 | 1 gives no overshoot at the reference mass or inertia. Raise positionDampingRatio for heavy objects that overshoot; lower values oscillate |
referenceMass, referenceInertia |
1 kg, 0.14 kg·m² | Mass and inertia at which the frequencies hold, not the object's own |
maxForce |
200 N | Cap of the arm force, against spikes of the hand velocity estimate |
maxTorque |
10 N·m | Cap of the wrist torque: how hard a long object pressed against an obstacle resists turning in the hand |
handVelocityFeedForward |
on | The object moves with the hand instead of lagging behind it. Keep it on |
handVelocitySmoothingFrequency |
10 Hz | Smoothing of the hand velocity estimate: lower values are smoother, but lag more |
exactStiffnessInContact, dampingFromObjectMass, noRigidbodyDampingWhileGrabbed |
off | Experimental variants: leave them off |
Grip failure
The limits, durations and strength are gameplay choices: how hard an object can be pushed or yanked before it slips. The ghost's warning color follows the grip limits, and if you change them, scale the ghost's fullDistance and fullAngle with them.
| Field | Default | What it does |
|---|---|---|
gripFailureMode |
Stagger | Stagger: the springs weaken for a moment, then recover. None: the grip never fails, for objects that must never slip |
maxGripDistance, maxGripAngle |
0.2 m, 60° | Gap above which the grip fails. The vibration then reaches its full amplitude at maxGripDistance (with None, at the rig part's 0.3 m) |
maxGripDistanceGrowth, maxGripAngleGrowth |
3 m/s, 720°/s | The grip fails when the gap grows faster than this: a yank, or a hand still moving at this speed when an obstacle stops the object |
staggerDuration |
0.3 s | Time during which the springs are weakened |
gripStrengthDuringStagger |
0.5 | Strength of the springs during a stagger: the object slips and sags, but stays in the hand. 0 lets it go |
recoveryDuration |
0.3 s | Time for the springs to get back their full strength |
onGripFailure |
Called on each client where the grip fails (see Networking) | |
teleportDistance |
0.8 m | Distance between the hand and the grab point above which the state authority moves the object to the hand at once, even through a wall (see Networking) |
Troubleshooting
Problems shared with the velocity follow (setup, collisions, release, ghost) are in the physics grabbing troubleshooting.
| Symptom | What to check |
|---|---|
| A held object lags behind the hand; heavy objects are slow | The springs have the same strength whatever the object. Raise positionFrequency or rotationFrequency, or use the velocity follow for tools that must stay in the hand |
| A heavy object overshoots when the hand stops | Raise its positionDampingRatio (the tuning readout shows the ratio it gets) |
| The object slips from the hand when pushed against something | The gap passed maxGripDistance or maxGripAngle, and the grip failed. Raise them, or set gripFailureMode to None |
| The object slips during a swing that hits nothing | A tracking glitch made the hand jump (a short stagger), or the growth limits are too low: raise maxGripDistanceGrowth and maxGripAngleGrowth |
| A grip failure effect (damage, score) is applied once per user | onGripFailure fires on each client where the grip fails: apply the effect on the state authority only |
| On other users' screens, a short teleport of the holder looks like a fast drag | Their view of the remote rig is interpolated, and a short jump can pass for a fast move. There is no setting for it yet |
Last updated on
Back to top