-
Notifications
You must be signed in to change notification settings - Fork 29
Grabbables
BaseGrabber.cs
is the script added to the hand itself that informs the objects that they are going to be grabbed, released or moved, while Grabbable.cs
takes care of the logic to follow the hand.
The Grabber-Grabbable pair is mostly agnostic from the rest of the snapping code. For a custom implementation, one could inherit from BaseGrabber
, but the only real requisite is that your grabber implements the interface IGrabNotifier
.
This interface is the only connection between the snapping system and the grabber-grabbable. It comprehends some Actions
indicating the current state of the grab, as well as some methods to indicate how close it is to a grabbable. Check the implementation in BaseGrabber
to study how to use it.
This is an abstract
class, which means you will need to inherit from it and implement the relevant methods in order for the grabber to be able to receive data from your current VR SDK. The script GrabbedHybridOVR.cs
provided is an example of this, using Oculus SDK to grab objects with either a controller or a hand, follow it as an example should you want to provide a grabber that works with SteamVR for example.
The code contains two sample grabbable that can be used directly in your project, but you could implement your own (together with an implementation for the Grabber):
This is the simplest grabbable, it will attach itself to the hand following the position and rotation offset at the GrabBegin event to move its transform as if it was parented to the hand, without actually being parented.
This grabbable attaches itself to the hand using a Joint. By default it will use a FixedJoint
but it is possible to create any type of joint in the editor and set it as the Custom Joint
variable, the grabbable will make sure to replicate such joint every time the GrabBegins. This is specially handy for grabbing objects with constraints, such as levers, or some weight like a heavy sword.
Good practices for joints:
- If you are using Joints to keep your object connected to other rigidbodies: make sure
pre-processing
is enabled in the Joint. This helps with stability when grabbing with a different Joint. - It is usually better to use
Configurable Joints
overHinge Joints
. When using the former, enabling reprojection might ensure the objects do not go to undesired poses. - If the object is attached to the world with a Joint and you are grabbing it with a
Custom Joint
, disablepre-processing
in theCustom Joint
so it does not "fight" with the world one over the final pose. - The
Custom Joint
should be in a disabled GameObject (or even a Prefab). It is used just for reference and should not affect the real world. - In the
Custom Joint
, set asFree
(using configurable joints) all the axis for translation and rotation that are not required. For example if you are creating a Lever that just moves forwards in local X, set as Lock just the X translation and free everything else.
The PhysicsGrabbable
is specially interesting in pair with the Hand Sliding feature described in Snapping Behaviours