Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


BoxCast

Casts the box along a ray and returns detailed information on what was hit.
Read time 2 minutesLast updated 4 days ago

Definition

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

BoxCast(Vector3, Vector3, Vector3, RaycastHit, Quaternion, float, int, QueryTriggerInteraction)

Casts the box along a ray and returns detailed information on what was hit.
public bool BoxCast(Vector3 center, Vector3 halfExtents, Vector3 direction, out RaycastHit hitInfo, Quaternion orientation, float maxDistance = Infinity, int layerMask = -5, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)

Parameters

center

Center of the box.

halfExtents

Half the size of the box in each dimension.

direction

The direction in which to cast the box.

hitInfo

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

orientation

Rotation of the box.

maxDistance

The max length of the cast.

layerMask

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

queryTriggerInteraction

Specifies whether this query should hit Triggers.

Returns

Type

Description

boolTrue, if any intersections were found.

Remarks

Additional Resources: Physics.BoxCast, RaycastHit

BoxCast(Vector3, Vector3, Vector3, RaycastHit[], Quaternion, float, int, QueryTriggerInteraction)

Casts the box along a ray and returns detailed information on what was hit.
public int BoxCast(Vector3 center, Vector3 halfExtents, Vector3 direction, RaycastHit[] results, Quaternion orientation, float maxDistance = Infinity, int layerMask = -5, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal)

Parameters

center

Center of the box.

halfExtents

Half the size of the box in each dimension.

direction

The direction in which to cast the box.

The buffer to store the results in.

orientation

Rotation of the box.

maxDistance

The max length of the cast.

layerMask

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

queryTriggerInteraction

Specifies whether this query should hit Triggers.

Returns

Type

Description

intThe amount of hits stored to the
results
buffer.

Remarks

Additional Resources: Physics.BoxCastNonAlloc