# SphereCast

> Casts a sphere along a ray and returns detailed information on what was hit.

## Definition

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

## SphereCast(Vector3, float, Vector3, RaycastHit, float, int, QueryTriggerInteraction)

Casts a sphere along a ray and returns detailed information on what was hit.

```csharp
public bool SphereCast(Vector3 origin, float radius, Vector3 direction, out RaycastHit hitInfo, float maxDistance = Infinity, int layerMask = -5, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)
```

### Parameters

**** (\[Vector3]\(/engine/6000.6/script-reference/unityengine/vector3)): The center of the sphere at the start of the sweep.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The radius of the sphere.**** (\[Vector3]\(/engine/6000.6/script-reference/unityengine/vector3)): The direction into which to sweep the sphere.**** (\[RaycastHit]\(/engine/6000.6/script-reference/unityengine/raycasthit)): If true is returned, `hitInfo` will contain more information about where the collider was hit. (Additional Resources: [RaycastHit](/engine/6000.6/script-reference/unityengine/raycasthit.md)).**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The max length of the cast.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): A [Layer mask](/engine/6000.6/manual/working-with-gameobjects/layers.md) that is used to selectively filter which colliders are considered when casting a sphere.**** (\[QueryTriggerInteraction]\(/engine/6000.6/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 sphere sweep intersects any collider, otherwise false. |

### Remarks

Additional Resources: [Physics.SphereCast](/engine/6000.6/script-reference/unityengine/physics/spherecast.md).

## SphereCast(Vector3, float, Vector3, RaycastHit\[], float, int, QueryTriggerInteraction)

Cast sphere along the direction and store the results into buffer.

```csharp
public int SphereCast(Vector3 origin, float radius, Vector3 direction, RaycastHit[] results, float maxDistance = Infinity, int layerMask = -5, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)
```

### Parameters

**** (\[Vector3]\(/engine/6000.6/script-reference/unityengine/vector3)): The center of the sphere at the start of the sweep.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The radius of the sphere.**** (\[Vector3]\(/engine/6000.6/script-reference/unityengine/vector3)): The direction into which to sweep the sphere.**** (\[RaycastHit\[]]\(/engine/6000.6/script-reference/unityengine/raycasthit)): The buffer to save the results to.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The max length of the cast.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): A [Layer mask](/engine/6000.6/manual/working-with-gameobjects/layers.md) that is used to selectively filter which colliders are considered when casting a sphere.**** (\[QueryTriggerInteraction]\(/engine/6000.6/script-reference/unityengine/querytriggerinteraction)): Specifies whether this query should hit Triggers.

### Returns

| Type                                                       | Description                                        |
| ---------------------------------------------------------- | -------------------------------------------------- |
| [int](https://learn.microsoft.com/dotnet/api/system.int32) | The amount of hits stored to the `results` buffer. |

### Remarks

Additional Resources: SphereCastNonAllloc.
