# Ray2D

> A ray in 2D space.

## Definition

* **Type:** Struct
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule
* **Implements:** [IFormattable](https://learn.microsoft.com/dotnet/api/system.iformattable)

```csharp
public struct Ray2D : IFormattable
```

## Remarks

A *ray* is a line segment that extends from a point in space in a specified direction. Rays have a number of uses in Unity but the most common is probably *raycasting*. This technique involves tracing along the path of a ray from its origin to determine if it intersects with any objects. This is useful for plotting the paths of projectiles, determining lines of sight and implementing many common game mechanics.

Additional Resources: [Physics2D.Raycast](/engine/6000.7/script-reference/unityengine/physics2d/raycast.md), [Ray](/engine/6000.7/script-reference/unityengine/ray.md) class, [RaycastHit2D](/engine/6000.7/script-reference/unityengine/raycasthit2d.md) class.

## Constructors

| Constructor                                                                                                                            | Description                                                                                                                                                                                       |
| -------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Ray2D(UnityEngine.Vector2,UnityEngine.Vector2)](/engine/6000.7/script-reference/unityengine/ray2d/ctor.md#ray2d\(vector2-vector2\))   | Creates a 2D ray starting at [Ray2D.origin](/engine/6000.7/script-reference/unityengine/ray2d/origin.md) along [Ray2D.direction](/engine/6000.7/script-reference/unityengine/ray2d/direction.md). |
| [Ray2D(UnityEngine.Vector2@,UnityEngine.Vector2@)](/engine/6000.7/script-reference/unityengine/ray2d/ctor.md#ray2d\(vector2-vector2\)) | Creates a 2D ray starting at [Ray2D.origin](/engine/6000.7/script-reference/unityengine/ray2d/origin.md) along [Ray2D.direction](/engine/6000.7/script-reference/unityengine/ray2d/direction.md). |

## Properties

| Property                                                                    | Description                                   |
| --------------------------------------------------------------------------- | --------------------------------------------- |
| [direction](/engine/6000.7/script-reference/unityengine/ray2d/direction.md) | The direction of the ray in world space.      |
| [origin](/engine/6000.7/script-reference/unityengine/ray2d/origin.md)       | The starting point of the ray in world space. |

## Methods

| Method                                                                    | Description                                         |
| ------------------------------------------------------------------------- | --------------------------------------------------- |
| [GetPoint](/engine/6000.7/script-reference/unityengine/ray2d/getpoint.md) | Get a point that lies a given distance along a ray. |
| [ToString](/engine/6000.7/script-reference/unityengine/ray2d/tostring.md) | Returns a formatted string for this 2D ray.         |
