Guides

VRTK_CustomRaycast

Overview

A Custom Raycast allows to specify custom options for a Physics.Raycast.

A number of other scripts can utilise a Custom Raycast to further customise the raycasts that the scripts use internally.

For example, the VRTK_BodyPhysics script can be set to ignore trigger colliders when casting to see if it should teleport up or down to the nearest floor.

Inspector Parameters

  • Layers To Ignore: The layers to ignore when raycasting.
  • Trigger Interaction: Determines whether the ray will interact with trigger colliders.

Class Methods

Raycast/6

public static bool Raycast(VRTK_CustomRaycast customCast, Ray ray, out RaycastHit hitData, LayerMask ignoreLayers, float length = Mathf.Infinity, QueryTriggerInteraction affectTriggers = QueryTriggerInteraction.UseGlobal)

  • Parameters
    • VRTK_CustomRaycast customCast - The optional object with customised cast parameters.
    • Ray ray - The Ray to cast with.
    • out RaycastHit hitData - The raycast hit data.
    • LayerMask ignoreLayers - A layermask of layers to ignore from the raycast.
    • float length - The maximum length of the raycast.
    • QueryTriggerInteraction affectTriggers - Determines the trigger interaction level of the cast.
  • Returns
    • bool - Returns true if the raycast successfully collides with a valid object.

The Raycast method is used to generate a raycast either from the given CustomRaycast object or a default Physics.Raycast.

Linecast/6

public static bool Linecast(VRTK_CustomRaycast customCast, Vector3 startPosition, Vector3 endPosition, out RaycastHit hitData, LayerMask ignoreLayers, QueryTriggerInteraction affectTriggers = QueryTriggerInteraction.UseGlobal)

  • Parameters
    • VRTK_CustomRaycast customCast - The optional object with customised cast parameters.
    • Vector3 startPosition - The world position to start the linecast from.
    • Vector3 endPosition - The world position to end the linecast at.
    • out RaycastHit hitData - The linecast hit data.
    • LayerMask ignoreLayers - A layermask of layers to ignore from the linecast.
    • QueryTriggerInteraction affectTriggers - Determines the trigger interaction level of the cast.
  • Returns
    • bool - Returns true if the linecast successfully collides with a valid object.

The Linecast method is used to generate a linecast either from the given CustomRaycast object or a default Physics.Linecast.

CapsuleCast/9

public static bool CapsuleCast(VRTK_CustomRaycast customCast, Vector3 point1, Vector3 point2, float radius, Vector3 direction, float maxDistance, out RaycastHit hitData, LayerMask ignoreLayers, QueryTriggerInteraction affectTriggers = QueryTriggerInteraction.UseGlobal)

  • Parameters
    • VRTK_CustomRaycast customCast - The optional object with customised cast parameters.
    • Vector3 point1 - The center of the sphere at the start of the capsule.
    • Vector3 point2 - The center of the sphere at the end of the capsule.
    • float radius - The radius of the capsule.
    • Vector3 direction - The direction into which to sweep the capsule.
    • float maxDistance - The max length of the sweep.
    • out RaycastHit hitData - The capsulecast hit data.
    • LayerMask ignoreLayers - A layermask of layers to ignore from the capsulecast.
    • QueryTriggerInteraction affectTriggers - Determines the trigger interaction level of the cast.
  • Returns
    • bool - Returns true if the capsulecast successfully collides with a valid object.

The CapsuleCast method is used to generate a capsulecast either from the given CustomRaycast object or a default Physics.CapsuleCast.

BoxCast/9

public static bool BoxCast(VRTK_CustomRaycast customCast, Vector3 center, Vector3 halfExtents, Vector3 direction, Quaternion orientation, float maxDistance, out RaycastHit hitData, LayerMask ignoreLayers, QueryTriggerInteraction affectTriggers = QueryTriggerInteraction.UseGlobal)

  • Parameters
    • VRTK_CustomRaycast customCast - The optional object with customised cast parameters.
    • Vector3 center - The center of the box.
    • Vector3 halfExtents - Half the size of the box in each dimension.
    • Vector3 direction - The direction in which to cast the box.
    • Quaternion orientation - The rotation of the box.
    • float maxDistance - The max length of the cast.
    • out RaycastHit hitData - The boxcast hit data.
    • LayerMask ignoreLayers - A layermask of layers to ignore from the boxcast.
    • QueryTriggerInteraction affectTriggers - Determines the trigger interaction level of the cast.
  • Returns
    • bool - Returns true if the boxcast successfully collides with a valid object.

The BoxCast method is used to generate a boxcast either from the given CustomRaycast object or a default Physics.BoxCast.

CustomRaycast/3

public virtual bool CustomRaycast(Ray ray, out RaycastHit hitData, float length = Mathf.Infinity)

  • Parameters
    • Ray ray - The Ray to cast with.
    • out RaycastHit hitData - The raycast hit data.
    • float length - The maximum length of the raycast.
  • Returns
    • bool - Returns true if the raycast successfully collides with a valid object.

The CustomRaycast method is used to generate a raycast based on the options defined in the CustomRaycast object.

CustomLinecast/3

public virtual bool CustomLinecast(Vector3 startPosition, Vector3 endPosition, out RaycastHit hitData)

  • Parameters
    • Vector3 startPosition - The world position to start the linecast from.
    • Vector3 endPosition - The world position to end the linecast at.
    • out RaycastHit hitData - The linecast hit data.
  • Returns
    • bool - Returns true if the line successfully collides with a valid object.

The CustomLinecast method is used to generate a linecast based on the options defined in the CustomRaycast object.

CustomCapsuleCast/6

public virtual bool CustomCapsuleCast(Vector3 point1, Vector3 point2, float radius, Vector3 direction, float maxDistance, out RaycastHit hitData)

  • Parameters
    • Vector3 point1 - The center of the sphere at the start of the capsule.
    • Vector3 point2 - The center of the sphere at the end of the capsule.
    • float radius - The radius of the capsule.
    • Vector3 direction - The direction into which to sweep the capsule.
    • float maxDistance - The max length of the sweep.
    • out RaycastHit hitData - The capsulecast hit data.
  • Returns
    • bool - Returns true if the capsule successfully collides with a valid object.

The CustomCapsuleCast method is used to generate a capsulecast based on the options defined in the CustomRaycast object.

CustomBoxCast/6

public virtual bool CustomBoxCast(Vector3 center, Vector3 halfExtents, Vector3 direction, Quaternion orientation, float maxDistance, out RaycastHit hitData)

  • Parameters
    • Vector3 center - The center of the box.
    • Vector3 halfExtents - Half the size of the box in each dimension.
    • Vector3 direction - The direction in which to cast the box.
    • Quaternion orientation - The rotation of the box.
    • float maxDistance - The max length of the cast.
    • out RaycastHit hitData - The boxcast hit data.
  • Returns
    • bool - Returns true if the box successfully collides with a valid object.

The CustomBoxCast method is used to generate a boxcast based on the options defined in the CustomRaycast object.