VRTK_PhysicsSlider
extends VRTK_BasePhysicsControllable
Overview
A physics based slider.
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 slider.
Script Usage:
- Create a slider container GameObject and set the GameObject that is to become the slider as a child of the container.
- Place the
VRTK_PhysicsSlider
script onto the GameObject that is to become the slider.
The slider GameObject must not be at the root level and needs to have it's Transform position set to
0,0,0
. This is the reason for the container GameObject requirement. Any positioning of the slider must be set on the parent GameObject.
Inspector Parameters
- Maximum Length: The maximum length that the slider can be moved from the origin position across the
Operate Axis
. A negative value will allow it to move the opposite way. - Min Max Threshold: The normalized position the slider can be within the minimum or maximum slider positions before the minimum or maximum positions are considered reached.
- Position Target: The target position to move the slider towards given in a normalized value of
0f
(start point) to1f
(end point). - Resting Position: The position the slider when it is at the default resting point given in a normalized value of
0f
(start point) to1f
(end point). - Force Resting Position Threshold: The normalized threshold value the slider has to be within the
Resting Position
before the slider is forced back to theResting Position
if it is not grabbed. - Step Value Range: The minimum and the maximum step values for the slider to register along the
Operate Axis
. - Step Size: The increments the slider value will change in between the
Step Value Range
. - Use Step As Value: If this is checked then the value for the slider will be the step value and not the absolute position of the slider Transform.
- Snap To Step: If this is checked then the slider will snap to the position of the nearest step along the value range.
- Snap Force: The speed in which the slider will snap to the relevant point 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 slider before it is automatically released.
- Release Friction: The amount of friction to the slider Rigidbody when it is released.
- Only Interact With: A collection of GameObjects that will be used as the valid collisions to determine if the door can be interacted with.
Class Methods
GetValue/0
public override float GetValue()
- Parameters
- none
- Returns
float
- The actual position of the button.
The GetValue method returns the current position value of the slider.
GetNormalizedValue/0
public override float GetNormalizedValue()
- Parameters
- none
- Returns
float
- The normalized position of the button.
The GetNormalizedValue method returns the current position value of the slider normalized between 0f
and 1f
.
SetValue/1
public override void SetValue(float value)
- Parameters
float value
- The new position value
- Returns
- none
The SetValue method sets the current position value of the slider
GetStepValue/1
public virtual float GetStepValue(float currentValue)
- Parameters
float currentValue
- The current position value of the slider to get the Step Value for.
- Returns
float
- The current Step Value based on the slider position.
The GetStepValue method returns the current position of the slider based on the step value range.
SetPositionTargetWithStepValue/1
public virtual void SetPositionTargetWithStepValue(float givenStepValue)
- Parameters
float givenStepValue
- The step value within theStep Value Range
to set thePosition Target
parameter to.
- Returns
- none
The SetTargetPositionWithStepValue sets the Position Target
parameter but uses a value within the Step Value Range
.
SetRestingPositionWithStepValue/1
public virtual void SetRestingPositionWithStepValue(float givenStepValue)
- Parameters
float givenStepValue
- The step value within theStep Value Range
to set theResting Position
parameter to.
- Returns
- none
The SetRestingPositionWithStepValue sets the Resting Position
parameter but uses a value within the Step Value Range
.
GetPositionFromStepValue/1
public virtual float GetPositionFromStepValue(float givenStepValue)
- Parameters
float givenStepValue
- The step value to check the position for.
- Returns
float
- The position the slider would be at based on the given step value.
The GetPositionFromStepValue returns the position the slider would be at based on the given step value.
IsResting/0
public override bool IsResting()
- Parameters
- none
- Returns
bool
- Returnstrue
if the slider is at the resting position or within the resting position threshold.
The IsResting method returns whether the slider is currently in a resting state at the resting position or within the resting position threshold and not grabbed.
GetControlJoint/0
public virtual ConfigurableJoint GetControlJoint()
- Parameters
- none
- Returns
ConfigurableJoint
- 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.
Updated less than a minute ago