Physics

Use these methods to interact with Unity’s physics engine.

Static members

Member

Description

gravity

The gravity applied to physics objects.

Static methods

Method

Description

CheckBox(center, halfExtents, orientation, target)

CheckCapsule(start, end, radius, target)

CheckSphere(position, radius, target)

Linecast(start, end, target)

Casts a ray from start to end until it collides with a target.

OverlapBox(center, halfExtents, orientation, target)

OverlapCapsule(start, end, radius, target)

OverlapSphere(position, radius, target)

Raycast(ray, range, target)

Casts a ray through the scene until it collides with a target.

RaycastAll(ray, range, target)

Casts a ray through the scene registering all collisions with target objects.

Spherecast(ray, radius, range, target)

Casts a sphere ray from start to end until it collides with a target.

SpherecastAll(ray, radius, range, target)

Casts a sphere ray from start to end until it collides with a target.

Details

class Physics
static Vector3 gravity

The gravity applied to physics objects.

static bool CheckBox(Vector3 center, Vector3 halfExtents, Quaternion orientation, RaycastTarget target)
static bool CheckCapsule(Vector3 start, Vector3 end, float radius, RaycastTarget target)
static bool CheckSphere(Vector3 position, float radius, RaycastTarget target)
static object Linecast(Vector3 start, Vector3 end, RaycastTarget target)

Casts a ray from start to end until it collides with a target.

Returns:

A RaycastHit if a collision occurs along the ray; otherwise nil.

static array<Collider> OverlapBox(Vector3 center, Vector3 halfExtents, Quaternion orientation, RaycastTarget target)
static array<Collider> OverlapCapsule(Vector3 start, Vector3 end, float radius, RaycastTarget target)
static array<Collider> OverlapSphere(Vector3 position, float radius, RaycastTarget target)
static object Raycast(Ray ray, float range, RaycastTarget target)

Casts a ray through the scene until it collides with a target.

Parameters:
  • ray – Test for collisions along this ray.

  • range – Look no further than this [meters].

  • target – Test for collisions with these things.

Returns:

A RaycastHit if a collision occurs along the ray; otherwise nil.

static array<RaycastHit> RaycastAll(Ray ray, float range, RaycastTarget target)

Casts a ray through the scene registering all collisions with target objects.

Parameters:
  • ray – Test for collisions along this ray.

  • range – Look no further than this [meters].

  • target – Test for collisions with these things.

Returns:

An array of RaycastHits that occured along the ray.

static object Spherecast(Ray ray, float radius, float range, RaycastTarget target)

Casts a sphere ray from start to end until it collides with a target.

Returns:

A RaycastHit if a collision occurs along the ray; otherwise nil.

static object SpherecastAll(Ray ray, float radius, float range, RaycastTarget target)

Casts a sphere ray from start to end until it collides with a target.

Returns:

A RaycastHit if a collision occurs along the ray; otherwise nil.