> ## Documentation Index
> Fetch the complete documentation index at: https://ugcore.urging.ch/llms.txt
> Use this file to discover all available pages before exploring further.

# UgLib.Raycast and Screen

> Line-of-sight tests and screen positions.

<Badge color="green">Client</Badge> Runs in your resource.

## Raycast

```lua theme={"dark"}
UgLib.Raycast.FromCoords(from, to, options?) -> result
UgLib.Raycast.FromCamera(distance?, options?) -> result
```

<ResponseField name="options.flags" type="integer" default="511">What the ray hits. 511 is everything.</ResponseField>
<ResponseField name="options.ignore" type="integer">An entity to ignore. `FromCamera` ignores the local player by default.</ResponseField>

<ResponseField name="result" type="table">
  `{ hit, coords?, normal?, entity?, material? }`. `entity` is nil for the world.
</ResponseField>

Shape tests are asynchronous: both MUST run in a thread and wait at most 1 second. `FromCamera` casts `distance` meters (default 10) from the gameplay camera.

## Screen

```lua theme={"dark"}
UgLib.Screen.WorldToScreen(coords) -> onScreen, x, y
UgLib.Screen.GetResolution() -> width, height
UgLib.Screen.GetAspectRatio() -> number
```

`x` and `y` go from 0 to 1.

## Example

```lua client.lua theme={"dark"}
CreateThread(function()
    local result = UgLib.Raycast.FromCamera(5.0)

    if result.hit and result.entity and IsEntityAVehicle(result.entity) then
        print('Looking at a vehicle')
    end
end)
```


## Related topics

- [UgLib.Notify](/ug-lib/notify.md)
- [UgLib.TextUI](/ug-lib/textui.md)
- [UgLib.Version](/ug-lib/version.md)
- [UgLib.Enums](/ug-lib/enums.md)
- [UgLib.Locale](/ug-lib/locale.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.