Guides

VRTK_PhysicsRotator

extends VRTK_BasePhysicsControllable

Overview

A physics based rotatable object.

Required Components:

  • Collider - A Unity Collider to determine when an interaction has occured. Can be a compound collider set in child GameObjects. Will be automatically added at runtime.
  • Rigidbody - A Unity Rigidbody to allow the GameObject to be affected by the Unity Physics System. Will be automatically added at runtime.

Optional Components:

  • VRTK_ControllerRigidbodyActivator - A Controller Rigidbody Activator to automatically enable the controller rigidbody when near the rotator.

Script Usage:

  • Create a rotator container GameObject and set the GameObject that is to become the rotator as a child of the newly created container GameObject.
  • Place the VRTK_PhysicsRotator script onto the GameObject that is to become the rotatable object and ensure the Transform rotation is 0, 0, 0.
  • Create a nested GameObject under the rotator GameObject and position it where the hinge should operate.
  • Apply the nested hinge GameObject to the Hinge Point parameter on the Physics Rotator script.

The rotator GameObject must not be at the root level and needs to have the Transform rotation set to 0,0,0. This is the reason for the container GameObject requirement. Any positioning of the rotator must be set on the parent container GameObject.

Inspector Parameters

  • Hinge Point: A Transform that denotes the position where the rotator hinge will be created.
  • Angle Limits: The minimum and maximum angle the rotator can rotate to.
  • Min Max Threshold Angle: The angle at which the rotator rotation can be within the minimum or maximum angle before the minimum or maximum angles are considered reached.
  • Resting Angle: The angle at which will be considered as the resting position of the rotator.
  • Force Resting Angle Threshold: The threshold angle from the Resting Angle that the current angle of the rotator needs to be within to snap the rotator back to the Resting Angle.
  • Angle Target: The target angle to rotate the rotator to.
  • Is Locked: If this is checked then the rotator Rigidbody will have all rotations frozen.
  • Step Value Range: The minimum and the maximum step values for the rotator to register along the Operate Axis.
  • Step Size: The increments the rotator value will change in between the Step Value Range.
  • Use Step As Value: If this is checked then the value for the rotator will be the step value and not the absolute rotation of the rotator Transform.
  • Snap To Step: If this is checked then the rotator will snap to the angle of the nearest step along the value range.
  • Snap Force: The speed in which the rotator will snap to the relevant angle along the Operate Axis
  • Grab Mechanic: The type of Interactable Object grab mechanic to use when operating the rotator.
  • Precision Grab: If this is checked then when the Interact Grab grabs the Interactable Object, it will grab it with precision and pick it up at the particular point on the Interactable Object that the Interact Touch is touching.
  • Detach Distance: The maximum distance the grabbing object is away from the rotator before it is automatically released.
  • Use Friction Overrides: If this is checked then the Grabbed Friction value will be used as the Rigidbody drag value when the rotator is grabbed and the Released Friction value will be used as the Rigidbody drag value when the door is released.
  • Grabbed Friction: The Rigidbody drag value when the rotator is grabbed.
  • Released Friction: The Rigidbody drag value when the rotator is released.
  • Only Interact With: A collection of GameObjects that will be used as the valid collisions to determine if the rotator can be interacted with.

Class Variables

  • public enum GrabMechanic - Type of Grab Mechanic
    • TrackObject - The Track Object Grab Mechanic
    • RotatorTrack - The Rotator Track Grab Mechanic

Class Methods

GetValue/0

public override float GetValue()

  • Parameters
    • none
  • Returns
    • float - The actual rotation of the rotator.

The GetValue method returns the current rotation value of the rotator.

GetNormalizedValue/0

public override float GetNormalizedValue()

  • Parameters
    • none
  • Returns
    • float - The normalized rotation of the rotator.

The GetNormalizedValue method returns the current rotation value of the rotator normalized between 0f and 1f.

SetValue/1

public override void SetValue(float value)

  • Parameters
    • float value - The new rotation value
  • Returns
    • none

The SetValue method sets the current Angle of the rotator

GetStepValue/1

public virtual float GetStepValue(float currentValue)

  • Parameters
    • float currentValue - The current angle value of the rotator to get the Step Value for.
  • Returns
    • float - The current Step Value based on the rotator angle.

The GetStepValue method returns the current angle of the rotator based on the step value range.

SetAngleTargetWithStepValue/1

public virtual void SetAngleTargetWithStepValue(float givenStepValue)

  • Parameters
    • float givenStepValue - The step value within the Step Value Range to set the Angle Target parameter to.
  • Returns
    • none

The SetAngleTargetWithStepValue sets the Angle Target parameter but uses a value within the Step Value Range.

SetRestingAngleWithStepValue/1

public virtual void SetRestingAngleWithStepValue(float givenStepValue)

  • Parameters
    • float givenStepValue - The step value within the Step Value Range to set the Resting Angle parameter to.
  • Returns
    • none

The SetRestingAngleWithStepValue sets the Resting Angle parameter but uses a value within the Step Value Range.

GetAngleFromStepValue/1

public virtual float GetAngleFromStepValue(float givenStepValue)

  • Parameters
    • float givenStepValue - The step value to check the angle for.
  • Returns
    • float - The angle the rotator would be at based on the given step value.

The GetAngleFromStepValue returns the angle the rotator would be at based on the given step value.

IsResting/0

public override bool IsResting()

  • Parameters
    • none
  • Returns
    • bool - Returns true if the rotator is at the resting angle or within the resting angle threshold.

The IsResting method returns whether the rotator is at the resting angle or within the resting angle threshold.

GetControlJoint/0

public virtual HingeJoint GetControlJoint()

  • Parameters
    • none
  • Returns
    • HingeJoint - The joint associated with the control.

The GetControlJoint method returns the joint associated with the control.

GetControlInteractableObject/0

public virtual VRTK_InteractableObject GetControlInteractableObject()

  • Parameters
    • none
  • Returns
    • VRTK_InteractableObject - The Interactable Object associated with the control.

The GetControlInteractableObject method returns the Interactable Object associated with the control.


Did this page help you?