text
stringlengths 0
1.11k
|
|---|
Replace the script’s existing code with this code, which will cause whichever controller you grab with to vibrate.
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using Oculus.Interaction;
|
using Oculus.Interaction.Input;
|
public class ReadData : MonoBehaviour
|
{
|
OVRInput.Controller leftController = OVRInput.Controller.LTouch;
|
OVRInput.Controller rightController = OVRInput.Controller.RTouch;
|
private void StartHaptics(Handedness handedness) {
|
if (handedness == Handedness.Left && OVRInput.IsControllerConnected(leftController)) {
|
OVRInput.SetControllerVibration(0.9f, 0.5f, leftController);
|
}
|
if (handedness == Handedness.Right && OVRInput.IsControllerConnected(rightController)) {
|
OVRInput.SetControllerVibration(0.9f, 0.5f, rightController);
|
}
|
}
|
public void HandlePointerEvent(PointerEvent pointerEvent) {
|
HandRef handData = (HandRef)pointerEvent.Data;
|
Handedness handedness = handData.Handedness;
|
StartHaptics(handedness);
|
}
|
}
|
Under Hierarchy, select CopyCube > HandGrabInteractable. This is the object that will read Data.
|
Under Inspector, add the ReadData script to HandGrabInteractable.
|
In the Pointable Unity Event Wrapper component, in the When Select section, add ReadData’s HandlePointerEvent function.
|
Adding function to Select event
|
Prepare to launch your scene by going to File > Build Settings and clicking the Add Open Scenes button.
|
Your scene is now ready to build.
|
Select File > Build And Run.
|
When the scene loads, grab the cube using one or both of your controllers. When you grab the cube, the controller that grabbed it will vibrate, and the hand visual will shake slightly.
|
Related topics
|
To learn more about Pointer Events, which you used in this tutorial, see Pointer Events.Throw an Object
|
Unity
|
All-In-One VR
|
Quest
|
The platform for which this article is written (Unity) does not match your preferred platform (Nativa).
|
Haz clic aquí para ver la página del índice de la documentación para tu plataforma de preferencia.
|
In this tutorial, you learn how to throw a cube with Interaction SDK using physics, velocity, and hand grab interactions.
|
Before you begin
|
Complete Getting Started with Interaction SDK.
|
Add a grab interaction via Add an Interaction with Quick Actions (if you’re using v62+), or Create Hand Grab Interactions (if you’re using legacy versions).
|
Add components to cube
|
In order to make the cube throwable, it has to respond to physics and an interaction (which in this tutorial is hand grab).
|
Open the Unity scene where you completed Getting Started with Interaction SDK.
|
Under Hierarchy, add a cube GameObject by right-clicking and selecting 3D Object > Cube.
|
Under Inspector, add these components.
|
Physics Grabbable
|
RigidBody
|
Grabbable
|
Hand Grab Interactable
|
In the Physics Grabbable component, set the Grabbable field to Cube.
|
Set the RigidBody property to Cube.
|
Physics Grabbable component properties
|
In the Hand Grab Interactable component, set the Physics Grabbable property to Cube.
|
Physics grabbable property
|
Add velocity components to hands
|
To determine the velocity of your hand and apply that velocity to the cube once you throw it, you’ll use the HandVelocityCalculator prefab.
|
Under Hierarchy, select LeftHand.
|
In the Project window’s search bar, search for HandVelocityCalculator. Ensure the search filter is set to either All or In Packages, since the default setting only searches your assets.
|
Drag the HandVelocityCalculator prefab from the search results onto the LeftHand GameObject in the Hierarchy.
|
Under Inspector, in the Hand Pose Input Device component, set the Hand property to LeftHand.
|
Under Hierarchy, select the left hand’s HandGrabInteractor, which is located at LeftHand > HandInteractorsLeft > HandGrabInteractor.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.