codeAPI Reference
Sandbox.VrAnchor
Sandbox.VrAnchor
Locks VR player position.
Overview
VrAnchor locks the player's playspace to a GameObject's transform. Essential for seated VR, vehicles, and room-scale setup.
Setup
CSHARP
[RequireComponent]
public VrAnchor Anchor { get; set; }Usage
CSHARP
// The VR player's view is locked to this GameObject
// Moving the GameObject moves the player
// Vehicle VR - player moves with vehicle
public class Vehicle : Component
{
[RequireComponent]
public VrAnchor Anchor { get; set; }
protected override void OnUpdate()
{
// Player automatically follows vehicle
WorldPosition += Velocity * Time.Delta;
}
}Seated Experience
CSHARP
// Lock player to chair position
var chair = new GameObject("Chair");
chair.WorldPosition = seatPosition;
chair.Components.Create<VrAnchor>();
// Player's view is now at chair height/positionRecentering
CSHARP
// Recenter playspace to current anchor position
Anchor.Recenter();Properties
Related
- VrTrackedObject — Track individual devices
- VrHand — Hand/finger tracking
Was this helpful?