Class XRRig
The XR Rig component is typically attached to the base object of the XR Rig, and stores the GameObject that will be manipulated via locomotion. It is also used for offsetting the camera.
Inherited Members
Namespace: UnityEngine.XR.Interaction.Toolkit
Syntax
[AddComponentMenu("XR/XR Rig")]
[DisallowMultipleComponent]
public class XRRig : MonoBehaviour
Properties
cameraFloorOffsetObject
The GameObject to move to desired height off the floor (defaults to this object if none provided).
Declaration
public GameObject cameraFloorOffsetObject { get; set; }
Property Value
Type | Description |
---|---|
GameObject |
cameraGameObject
The GameObject that contains the camera, this is usually the "Head" of XR rigs.
Declaration
public GameObject cameraGameObject { get; set; }
Property Value
Type | Description |
---|---|
GameObject |
cameraInRigSpaceHeight
(Read Only) The camera's height relative to the rig.
Declaration
public float cameraInRigSpaceHeight { get; }
Property Value
Type | Description |
---|---|
Single |
cameraInRigSpacePos
(Read Only) The camera's local position in rig space.
Declaration
public Vector3 cameraInRigSpacePos { get; }
Property Value
Type | Description |
---|---|
Vector3 |
cameraYOffset
The amount the camera is offset from the floor (by moving the camera offset object).
Declaration
public float cameraYOffset { get; set; }
Property Value
Type | Description |
---|---|
Single |
rig
The "Rig" GameObject is used to refer to the base of the XR Rig, by default it is this GameObject. This is the GameObject that will be manipulated via locomotion.
Declaration
public GameObject rig { get; set; }
Property Value
Type | Description |
---|---|
GameObject |
rigInCameraSpacePos
(Read Only) The rig's local position in camera space.
Declaration
public Vector3 rigInCameraSpacePos { get; }
Property Value
Type | Description |
---|---|
Vector3 |
trackingSpace
Whether the experience is rooms scale or stationary. Not all devices support all tracking spaces; if the selected tracking space is not set it will fall back to Stationary.
Declaration
public TrackingSpaceType trackingSpace { get; set; }
Property Value
Type | Description |
---|---|
TrackingSpaceType |
Methods
Awake()
Declaration
protected void Awake()
MatchRigUp(Vector3)
This function will rotate the rig object such that the rig's up vector will match the provided vector.
Declaration
public bool MatchRigUp(Vector3 destinationUp)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | destinationUp | the vector to which the rig object's up vector will be matched. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the rotation is performed or the vectors have already been matched. Returns false otherwise. |
MatchRigUpCameraForward(Vector3, Vector3)
This function will rotate the rig object around the camera object using the destinationUp
vector such that:
Declaration
public bool MatchRigUpCameraForward(Vector3 destinationUp, Vector3 destinationForward)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | destinationUp | The up vector that the rig's up vector will be matched to. |
Vector3 | destinationForward | The forward vector that will be matched to the projection of the camera's forward vector on the plane with the normal |
Returns
Type | Description |
---|---|
Boolean | Returns true if the rotation is performed. Returns false otherwise. |
MatchRigUpRigForward(Vector3, Vector3)
This function will rotate the rig object around the camera object using the destinationUp
vector such that:
Declaration
public bool MatchRigUpRigForward(Vector3 destinationUp, Vector3 destinationForward)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | destinationUp | The up vector that the rig's up vector will be matched to. |
Vector3 | destinationForward | The forward vector that will be matched to the forward vector of the rig object, which is the direction the player moves in Unity when walking forward in the physical world. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the rotation is performed. Returns false otherwise. |
MoveCameraToWorldLocation(Vector3)
This function moves the camera to the world location provided by desiredWorldLocation. It does this by moving the rig object so that the camera's world location matches the desiredWorldLocation
Declaration
public bool MoveCameraToWorldLocation(Vector3 desiredWorldLocation)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | desiredWorldLocation | the position in world space that the camera should be moved to |
Returns
Type | Description |
---|---|
Boolean | Returns true if the move is performed. Returns false otherwise. |
OnDrawGizmos()
Declaration
protected virtual void OnDrawGizmos()
OnValidate()
Declaration
protected void OnValidate()
RotateAroundCameraPosition(Vector3, Single)
Rotates the rig object around the camera object's position in world space using the provided vector
as the rotation axis. The rig object is rotated by the amount of degrees provided in angleDegrees
.
Declaration
public bool RotateAroundCameraPosition(Vector3 vector, float angleDegrees)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | vector | The axis of the rotation. |
Single | angleDegrees | The amount of rotation in degrees. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the rotation is performed. Returns false otherwise. |
RotateAroundCameraUsingRigUp(Single)
Rotates the rig object around the camera object by the provided angleDegrees
.
This rotation only occurs around the rig's Up vector
Declaration
public bool RotateAroundCameraUsingRigUp(float angleDegrees)
Parameters
Type | Name | Description |
---|---|---|
Single | angleDegrees | The amount of rotation in degrees. |
Returns
Type | Description |
---|---|
Boolean | Returns true if the rotation is performed. Returns false otherwise. |
Start()
Declaration
protected void Start()