VRTK_ArtificialRotator
extends VRTK_BaseControllable
Overview
A artificially simulated openable rotator.
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.
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_ArtificialRotator
script onto the GameObject that is to become the rotatable object and ensure the Transform rotation is0, 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 Artificial 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.
The Artificial Rotator script GameObject will become the child of a runtime created GameObject that determines the rotational offset for the rotator.
Inspector Parameters
- Hinge Point: A Transform that denotes the position where the rotator will rotate around.
- 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 theResting Angle
. - 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
- 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.
- Rotation Action: Determines how the rotation of the object is calculated based on the action of the grabbing object.
- Grabbed Friction: The simulated friction when the rotator is grabbed.
- Released Friction: The simulated friction 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 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
GetContainer/0
public virtual GameObject GetContainer()
- Parameters
- none
- Returns
GameObject
- The GameObject container of the rotator control.
The GetContainer method returns the GameObject that is generated to hold the rotator control.
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 theStep Value Range
to set theAngle 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 theStep Value Range
to set theResting 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.
SetAngleTarget/1
public virtual void SetAngleTarget(float newAngle)
- Parameters
float newAngle
- The angle in which to rotate the rotator to.
- Returns
- none
The SetAngleTarget method sets a target angle to rotate the rotator to.
IsResting/0
public override bool IsResting()
- Parameters
- none
- Returns
bool
- Returnstrue
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.
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.
Updated less than a minute ago