# getRayFromCoordinate

### getRayFromCoordinate

Converts normalized screen coordinates to a 3D ray from the camera.

#### Signature

```typescript
getRayFromCoordinate(x: number, y: number): Promise<Ray>
```

#### Parameters

<table><thead><tr><th width="120.078125">Parameter</th><th width="126.88671875">Type</th><th width="127.50390625">Required</th><th>Description</th></tr></thead><tbody><tr><td>x</td><td>number</td><td>Yes</td><td>Normalized X coordinate (0 = left, 1 = right)</td></tr><tr><td>y</td><td>number</td><td>Yes</td><td>Normalized Y coordinate (0 = top, 1 = bottom)</td></tr></tbody></table>

#### Returns

`Promise<Ray>` — Ray from camera through the screen point.

```typescript
type Ray = {
  start: Vector3;    // Ray origin (camera position)
  direction: Vector3; // Normalized direction vector
};
```

#### Usage

```javascript
// Get ray from center of canvas
const ray = await api.getRayFromCoordinate(0.5, 0.5);
console.log("Ray start:", ray.start);
console.log("Ray direction:", ray.direction);

// Get ray from click position
iframe.addEventListener("click", async (e) => {
  const rect = iframe.getBoundingClientRect();
  const x = (e.clientX - rect.left) / rect.width;
  const y = (e.clientY - rect.top) / rect.height;
  const ray = await api.getRayFromCoordinate(x, y);
  
  // Use with raycastObject
  const hit = await api.raycastObject("MyObject", ray);
});
```

#### Notes

* Coordinates are **normalized 0-1**, not pixels
* `(0, 0)` = top-left corner, `(1, 1)` = bottom-right corner
* `(0.5, 0.5)` = center of canvas
* Useful for custom click handling with `raycastObject()`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.vectary.com/api/model-api/api-reference/getrayfromcoordinate.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
