


| Mapping | Description |
|---|---|
RawButton.RIndexTrigger | Right controller’s index trigger |
RawButton.RThumbstickLeft | Right controller’s thumbstick press to left |
RawButton.RThumbstickRight | Right controller’s thumbstick press to right |
Button.One | Right controller’s A button |
Axis1D.PrimaryHandTrigger | Left controller’s hand trigger |
Secondary is the right and Primary is the left controller.OVRCameraRig to your project, follow these steps:

ControllerScript.cs.ControllerScript class, add the following variables: public Camera sceneCamera;
private Vector3 targetPosition;
private Quaternion targetRotation;
private float step;
sceneCamera represents the camera that the scene uses.targetPosition represents the position of the camera.targetRotation represents the rotation of the camera.step helps with animating the Cube GameObject.Start()Start() function, define the initial cube’s position. void Start()
{
transform.position = sceneCamera.transform.position + sceneCamera.transform.forward * 3.0f;
}
centerCube() function and add the following lines. void centerCube()
{
targetPosition = sceneCamera.transform.position + sceneCamera.transform.forward * 3.0f;
targetRotation = Quaternion.LookRotation(transform.position - sceneCamera.transform.position);
transform.position = Vector3.Lerp(transform.position, targetPosition, step);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, step);
}
centerCube() function smoothly places the cube GameObject in front of the user, at the center of their viewport, and rotates the cube according to the user’s headpose (camera).Update() function, define your step value to animate the cube. void Update()
{
step = 5.0f * Time.deltaTime;
}
OVRInput.RawButton.RIndexTrigger. This treats the trigger as a simple button. If the value is true, then the user currently presses that trigger, which means that you can invoke the centerCube() function and place / rotate the cube.Update() function:if (OVRInput.Get(OVRInput.RawButton.RIndexTrigger)) centerCube();
OVRInput.RawButton.RThumbstickLeft (user presses thumbstick to the left) and OVRInput.RawButton.RThumbstickRight (user presses thumbstick to the right). If any of these two values is true, then rotate the cube accordingly.Update() function: if (OVRInput.Get(OVRInput.RawButton.RThumbstickLeft)) transform.Rotate(0, 5.0f * step, 0);
if (OVRInput.Get(OVRInput.RawButton.RThumbstickRight)) transform.Rotate(0, -5.0f * step, 0);
OVRInput.Button.One. If true, the user has just released the A button.SetControllerVibration(), defined as OVRInput.SetControllerVibration(float frequency, float amplitude, Controller controllerMask). When using this function, remember the following about its parameters:amplitude are between zero and one, inclusive.amplitude, the stronger the vibration is.frequency to 1 to enable haptics.controllerMask can be OVRInput.Controller.RTouch, which represents the right controller, or OVRInput.Controller.LTouch, which represents the left controller.amplitude and frequency to zero.Update() function to enable haptic feedback on the right controler lasting for two seconds, after the user releases the A button. if (OVRInput.GetUp(OVRInput.Button.One))
{
OVRInput.SetControllerVibration(1, 1, OVRInput.Controller.RTouch);
}
OVRInput.Axis1D.PrimaryHandTrigger (user presses hand trigger).0.0f, then place the cube at the left controller’s position through OVRInput.GetLocalControllerPosition() and rotate it according to the left controller’s rotation through OVRInput.GetLocalControllerRotation(). Both accept a parameter that represents the controller.Update() function and save your script. if (OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger) > 0.0f)
{
transform.position = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch);
transform.rotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch);
}



ControllerScript.cs.using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ControllerScript : MonoBehaviour
{
public Camera sceneCamera;
private Vector3 targetPosition;
private Quaternion targetRotation;
private float step;
// Start is called before the first frame update
void Start()
{
// Set initial cube's position in front of user
transform.position = sceneCamera.transform.position + sceneCamera.transform.forward * 3.0f;
}
// Update is called once per frame
void Update()
{
// Define step value for animation
step = 5.0f * Time.deltaTime;
// While user holds the right index trigger, center the cube and turn it to face user
if (OVRInput.Get(OVRInput.RawButton.RIndexTrigger)) centerCube();
// While thumbstick of right controller is currently pressed to the left
// rotate cube to the left
if (OVRInput.Get(OVRInput.RawButton.RThumbstickLeft)) transform.Rotate(0, 5.0f * step, 0);
// While thumbstick of right controller is currently pressed to the right
// rotate cube to the right
if (OVRInput.Get(OVRInput.RawButton.RThumbstickRight)) transform.Rotate(0, -5.0f * step, 0);
// If user has just released Button A of right controller in this frame
if (OVRInput.GetUp(OVRInput.Button.One))
{
// Play short haptic on right controller
OVRInput.SetControllerVibration(1, 1, OVRInput.Controller.RTouch);
}
// While user holds the left hand trigger
if (OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger) > 0.0f)
{
// Assign left controller's position and rotation to cube
transform.position = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch);
transform.rotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch);
}
}
void centerCube()
// Places cube smoothly at the center of the user's viewport and rotates it to face the camera
{
targetPosition = sceneCamera.transform.position + sceneCamera.transform.forward * 3.0f;
targetRotation = Quaternion.LookRotation(transform.position - sceneCamera.transform.position);
transform.position = Vector3.Lerp(transform.position, targetPosition, step);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, step);
}
}