SphereCast
Casts a sphere along a ray and returns detailed information on what was hit.
Read time 2 minutesLast updated 10 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- 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.
public bool SphereCast(Vector3 origin, float radius, Vector3 direction, out RaycastHit hitInfo, float maxDistance = Infinity, int layerMask = -5, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)
Parameters
The center of the sphere at the start of the sweep.
The radius of the sphere.
The direction into which to sweep the sphere.
If true is returned, will contain more information about where the collider was hit. (Additional Resources: RaycastHit).
hitInfoThe max length of the cast.
A Layer mask that is used to selectively filter which colliders are considered when casting a sphere.
Specifies whether this query should hit Triggers.
Returns
Type | Description |
|---|---|
| bool | True when the sphere sweep intersects any collider, otherwise false. |
Remarks
Additional Resources: Physics.SphereCast.
SphereCast(Vector3, float, Vector3, RaycastHit[], float, int, QueryTriggerInteraction)
Cast sphere along the direction and store the results into buffer.
public int SphereCast(Vector3 origin, float radius, Vector3 direction, RaycastHit[] results, float maxDistance = Infinity, int layerMask = -5, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)
Parameters
The center of the sphere at the start of the sweep.
The radius of the sphere.
The direction into which to sweep the sphere.
The buffer to save the results to.
The max length of the cast.
A Layer mask that is used to selectively filter which colliders are considered when casting a sphere.
Specifies whether this query should hit Triggers.
Returns
Type | Description |
|---|---|
| int | The amount of hits stored to the |
Remarks
Additional Resources: SphereCastNonAllloc.