# RaycastHit2D

> Returns information about 2D Colliders detected by a 2D physics query in the scene.

## Definition

* **Type:** Struct
* **Namespace:** [UnityEngine](/engine/6000.0/script-reference/unityengine.md)
* **Assembly:** UnityEngine.Physics2DModule

```csharp
public struct RaycastHit2D
```

## Remarks

The RaycastHit2D struct is used to return results from many 2D physics queries. It contains many pieces of information about a detection result including the [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) detected along with extra detail such as the contact point, the distance traversed to that contact point, the contact normal at that contact point etc.

When using any physics query that returns a RaycastHit2D, you should always first check to see if it contains a valid result which indicates that a hit (intersection) was detected. You can do this by checking if the RaycastHit2D is `true` or `false` (see code examples). Also, when the result is invalid, all the RaycastHit2D fields will be at their default.

**NOTE**: This type is also used by the following physics queries:

Additional Resources: [Physics2D.Raycast](/engine/6000.0/script-reference/unityengine/physics2d/raycast.md), [Physics2D.Linecast](/engine/6000.0/script-reference/unityengine/physics2d/linecast.md), [Physics2D.BoxCast](/engine/6000.0/script-reference/unityengine/physics2d/boxcast.md), [Physics2D.CapsuleCast](/engine/6000.0/script-reference/unityengine/physics2d/capsulecast.md), [Physics2D.CircleCast](/engine/6000.0/script-reference/unityengine/physics2d/circlecast.md), [Physics2D.GetRayIntersection](/engine/6000.0/script-reference/unityengine/physics2d/getrayintersection.md), [Collider2D.Cast](/engine/6000.0/script-reference/unityengine/collider2d/cast.md), [Rigidbody2D.Cast](/engine/6000.0/script-reference/unityengine/rigidbody2d/cast.md), [PhysicsScene2D.Raycast](/engine/6000.0/script-reference/unityengine/physicsscene2d/raycast.md), [PhysicsScene2D.Linecast](/engine/6000.0/script-reference/unityengine/physicsscene2d/linecast.md), [PhysicsScene2D.BoxCast](/engine/6000.0/script-reference/unityengine/physicsscene2d/boxcast.md), [PhysicsScene2D.CapsuleCast](/engine/6000.0/script-reference/unityengine/physicsscene2d/capsulecast.md), [PhysicsScene2D.CircleCast](/engine/6000.0/script-reference/unityengine/physicsscene2d/circlecast.md) and [PhysicsScene2D.GetRayIntersection](/engine/6000.0/script-reference/unityengine/physicsscene2d/getrayintersection.md).

## Properties

| Property                                                                           | Description                                                                                                                                                                                                                                               |
| ---------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [centroid](/engine/6000.0/script-reference/unityengine/raycasthit2d/centroid.md)   | The world space centroid (center) of the physics query shape when it intersects.                                                                                                                                                                          |
| [collider](/engine/6000.0/script-reference/unityengine/raycasthit2d/collider.md)   | The [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) detected by the physics query.                                                                                                                                                |
| [distance](/engine/6000.0/script-reference/unityengine/raycasthit2d/distance.md)   | The distance the physics query traversed before it detected a [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md).                                                                                                                    |
| [fraction](/engine/6000.0/script-reference/unityengine/raycasthit2d/fraction.md)   | The fraction of the distance specified to the physics query before it detected a [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md).                                                                                                 |
| [normal](/engine/6000.0/script-reference/unityengine/raycasthit2d/normal.md)       | The surface normal of the detected [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md).                                                                                                                                               |
| [point](/engine/6000.0/script-reference/unityengine/raycasthit2d/point.md)         | The world space position where the physics query shape intersected with the detected [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) surface.                                                                                     |
| [rigidbody](/engine/6000.0/script-reference/unityengine/raycasthit2d/rigidbody.md) | The [Rigidbody2D](/engine/6000.0/script-reference/unityengine/rigidbody2d.md) that the [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) detected by the physics query is attached to.                                              |
| [transform](/engine/6000.0/script-reference/unityengine/raycasthit2d/transform.md) | The [Transform](/engine/6000.0/script-reference/unityengine/transform.md) on the [GameObject](/engine/6000.0/script-reference/unityengine/gameobject.md) that the [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) is attached to. |

## Operators

| Operator                                                                        | Description                                                                                           |
| ------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| [bool](/engine/6000.0/script-reference/unityengine/raycasthit2d/op-implicit.md) | Implicit operator used to return a `true` or `false` result indicating if the result is valid or not. |
