# SweepTest(Vector3, out RaycastHit, float, QueryTriggerInteraction)

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

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.PhysicsModule

## SweepTest(Vector3, RaycastHit, float, QueryTriggerInteraction)

```csharp
public bool SweepTest(Vector3 direction, out RaycastHit hitInfo, float maxDistance, QueryTriggerInteraction queryTriggerInteraction)
```

### Parameters

**** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): The direction into which to sweep the rigidbody.**** (\[RaycastHit]\(/engine/6000.7/script-reference/unityengine/raycasthit)): If true is returned, `hitInfo` will contain more information about where the collider was hit ().**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The length of the sweep.**** (\[QueryTriggerInteraction]\(/engine/6000.7/script-reference/unityengine/querytriggerinteraction)): Specifies whether this query should hit Triggers.

### Returns

| Type                                                          | Description                                                             |
| ------------------------------------------------------------- | ----------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True when the rigidbody sweep intersects any collider, otherwise false. |

### Remarks

Tests if a rigidbody would collide with anything, if it was moved through the Scene. This is similar to doing a [Physics.Raycast](/engine/6000.7/script-reference/unityengine/physics/raycast.md) for all points contained in any of a Rigidbody's colliders and returning the closest of all hits (if any) reported. This is useful for AI code, say if you need to know that an object would fit through a gap without colliding with anything.

Note that this function only works when a primitive collider type (sphere, cube or capsule) or a convex mesh is attached to the rigidbody object - concave mesh colliders will not work, although they can be detected in the Scene by the sweep.

Additional Resources: [Physics.SphereCast](/engine/6000.7/script-reference/unityengine/physics/spherecast.md), [Physics.CapsuleCast](/engine/6000.7/script-reference/unityengine/physics/capsulecast.md), [Rigidbody.SweepTestAll](/engine/6000.7/script-reference/unityengine/rigidbody/sweeptestall.md), [RaycastHit](/engine/6000.7/script-reference/unityengine/raycasthit.md)

### Examples

```csharp
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public float collisionCheckDistance;
    public bool aboutToCollide;
    public float distanceToCollision;
    public Rigidbody rb;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    void Update()
    {
        RaycastHit hit;
        if (rb.SweepTest(transform.forward, out hit, collisionCheckDistance))
        {
            aboutToCollide = true;
            distanceToCollision = hit.distance;
        }
    }
}
```
