Skip to main content

Rigidbody.SweepTest(Vector3 direction, number maxDistance = math.huge, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)

Tests if a rigidbody would collide with anything, if it was moved through the Scene.

Parameters:

NameTypeDescription
directionVector3The direction into which to sweep the rigidbody.
maxDistancenumberThe length of the sweep.
queryTriggerInteractionQueryTriggerInteractionSpecifies whether this query should hit Triggers.

Returns:

typeDescription
booleanTrue when the rigidbody sweep intersects any collider, otherwise false.
RaycastHitIf true is returned, hitInfo will contain more information about where the collider was hit

Usage

---@type Rigidbody
local rigidbody;

---@type Vector3
local direction;

---@type number
local maxDistance;

---@type QueryTriggerInteraction
local queryTriggerInteraction;


local val0, val1 = rigidbody.SweepTest(direction, maxDistance, queryTriggerInteraction)