# rigidbody

> The Rigidbody2D that the Collider2D detected by the physics query is attached to.

## Definition

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

```csharp
public Rigidbody2D rigidbody { get; }
```

### Remarks

When the [RaycastHit2D](/engine/6000.7/script-reference/unityengine/raycasthit2d.md) result is returned from a physics query, the `collider` refers to the specific [Collider2D](/engine/6000.7/script-reference/unityengine/collider2d.md) that was detected however `rigidbody` refers to the [Rigidbody2D](/engine/6000.7/script-reference/unityengine/rigidbody2d.md) the [Collider2D](/engine/6000.7/script-reference/unityengine/collider2d.md) is attached to.

In the case where the [Collider2D](/engine/6000.7/script-reference/unityengine/collider2d.md) is not attached to a [Rigidbody2D](/engine/6000.7/script-reference/unityengine/rigidbody2d.md) then `rigidbody` will be NULL.

**NOTE**: `rigidbody` is equivalent to using [\_attachedRigidbody](/engine/6000.7/script-reference/unityengine/collider2d/attachedrigidbody.md) and is provided for convenience only.

Additional Resources: [\_collider](/engine/6000.7/script-reference/unityengine/raycasthit2d/collider.md), [Rigidbody2D](/engine/6000.7/script-reference/unityengine/rigidbody2d.md)

### Examples

```csharp
using UnityEngine;

public class ExampleClass : MonoBehaviour
{
    public Vector2 direction;

    void Update()
    {
        // Cast a ray in the specified direction.
        RaycastHit2D hit = Physics2D.Raycast(transform.position, direction);

        // If something was hit and it was attached to a rigidbody then move the rigidbody to the world origin.
        if (hit && hit.rigidbody)
            hit.rigidbody.position = Vector2.zero;
    }
}
```
