Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


CapsuleCast

Casts a capsule against all colliders in this physics scene and returns detailed information on what was hit.
Read time 2 minutesLast updated 4 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine
  • Assembly: UnityEngine.PhysicsModule

CapsuleCast(Vector3, Vector3, float, Vector3, RaycastHit, float, int, QueryTriggerInteraction)

Casts a capsule against all colliders in this physics scene and returns detailed information on what was hit.
public bool CapsuleCast(Vector3 point1, Vector3 point2, float radius, Vector3 direction, out RaycastHit hitInfo, float maxDistance = Infinity, int layerMask = -5, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)

Parameters

point1

The center of the sphere at the
start
of the capsule.

point2

The center of the sphere at the
end
of the capsule.

radius

The radius of the capsule.

direction

The direction into which to sweep the capsule.

hitInfo

If true is returned,
hitInfo
will contain more information about where the collider was hit. ().

maxDistance

The max length of the sweep.

layerMask

A Layer mask that is used to selectively filter which colliders are considered when casting a capsule.

queryTriggerInteraction

Specifies whether this query should hit Triggers.

Returns

Type

Description

boolTrue when the capsule sweep intersects any collider, otherwise false.

Remarks

Additional Resources: Physics.CapsuleCast, RaycastHit

CapsuleCast(Vector3, Vector3, float, Vector3, RaycastHit[], float, int, QueryTriggerInteraction)

Casts a capsule against all colliders in this physics scene and returns detailed information on what was hit.
public int CapsuleCast(Vector3 point1, Vector3 point2, float radius, Vector3 direction, RaycastHit[] results, float maxDistance = Infinity, int layerMask = -5, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)

Parameters

point1

The center of the sphere at the
start
of the capsule.

point2

The center of the sphere at the
end
of the capsule.

radius

The radius of the capsule.

direction

The direction into which to sweep the capsule.

The buffer to store the results in.

maxDistance

The max length of the sweep.

layerMask

A Layer mask that is used to selectively filter which colliders are considered when casting a capsule.

queryTriggerInteraction

Specifies whether this query should hit Triggers.

Returns

Type

Description

intThe amount of hits stored to the
results
buffer.

Remarks

Additional Resources: Physics.CapsuleCastNonAlloc