XRShared Velocity Grabbing
VelocityPhysicsGrabbable is the velocity follow of physics grabbing, in the XRShared addon: it sets the held object's velocities toward the hand at each physics step, so the object follows the hand the same way whatever its mass. The physics grabbing page covers what both follows share, and the choice between them.
Overview
Setup
Follow the physics grabbing setup, with NetworkVelocityPhysicsGrabbable and VelocityPhysicsGrabbable as the follow's components.
The DemoPhysicsGrabbing scene uses variants of Runtime/Demo/PhysicsGrabbing/Prefabs/PhysiscsGrabbable.prefab (cube, cylinder, sphere). They use Continuous Speculative collision detection. In a copy, remove their demo parts: AuthorityVisualization (it colors the object by state authority) and the text label. The Line Drawing addon's NetworkLineDrawing Physics prefab turns finished drawings into velocity grabbed objects.
How it works
Why velocities
Setting velocities makes every object follow the hand the same way, whatever its mass, with nothing to tune per object. The price is that at each step the follow overwrites what the solver did, so a velocity-held object pushes as hard as the solver allows, and always wins against a force-held one.
At each physics step, the follow sets the velocities that bring the object part of the way to where the hand holds it: the grab point moves toward the hand, and the object turns toward the hand's rotation, around the grab point. Unity's physics step then solves the contacts with these velocities, and the next step sets them again. Closing the whole gap at each step would push too hard into contacts (jitter, tunneling), so the follow only closes part of it, and the object lags a little behind a moving hand.
Settings
The release and inertia settings shared with the force follow are on the physics grabbing page.
| Field | Default | What it does |
|---|---|---|
followVelocityAttenuation |
0.5 | Fraction of the grab point position error corrected at each physics step. Lower values give a softer follow, with more lag; higher ones a tighter follow that pushes harder in contacts |
followAngularVelocityAttenuation |
0.8 | Fraction of the rotation error corrected at each physics step. Lower values push less against other colliders (less jitter and tunneling in contacts), with more rotation lag |
maxVelocity |
10 m/s | Limit of the grab point velocity. It mostly matters after a teleport or a tracking loss: it limits how fast the object comes back |
maxAngularVelocity |
20 rad/s | Limit of the follow rotation, so that the far end of long objects does not go through thin colliders. While grabbed, the Rigidbody's own maxAngularVelocity (Project Settings > Physics > Default Max Angular Speed) is raised to it if lower, and restored on release |
centerOfMassAtGrabPoint |
on | Makes hits turn the object around the hand (why). Turn it off, with sameInertiaOnAllAxesWhileGrabbed, for objects whose mass distribution matters (a hammer) |
Troubleshooting
Problems shared with the force follow (setup, collisions, release, ghost) are in the physics grabbing troubleshooting.
| Symptom | What to check |
|---|---|
| The displayed hand jitters while a held object presses on another one | followAngularVelocityAttenuation too high |
| The held object rotates late during a fast flick | followAngularVelocityAttenuation or maxAngularVelocity too low |
| The follow feels different after a Fixed Timestep change | The attenuations are fractions corrected at each physics step, so a shorter step corrects faster. To keep the default feel at another step (Unity's default is 0.02 s), use 1 - (1 - attenuation)^(step / 0.02) for both (the same error left after 0.02 s) |
| The grabbing ignores the mass distribution of my object (a hammer) | centerOfMassAtGrabPoint and sameInertiaOnAllAxesWhileGrabbed replace it while the object is held: turn both off on this object |
| Hits turn the displayed hand into the obstacle, or the object turns too easily around one axis | centerOfMassAtGrabPoint or sameInertiaOnAllAxesWhileGrabbed turned off |
| The ghost shows during ordinary moves | The follow lags behind a moving hand: raise the ghost's showDistance and fullDistance above that lag |
| After a teleport, the held object flies across the room | It comes back to the hand at up to maxVelocity, colliding on the way. Lower maxVelocity for a slower return |
Last updated on
Back to top