> For the complete documentation index, see [llms.txt](https://jaipack17.gitbook.io/raycast2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jaipack17.gitbook.io/raycast2/getting-started/api.md).

# API

After you have installed the module. You should know how to use it. Here's the documentation for the module!

### RayCast2.new()

initializes the ray to be formed.\
\
-> parameters\
`origin [Vector2] or [UDim2]`\
`direction [Vector2] or [UDim2]`\
\
origin: Starting point of the ray\
direction: Direction point of the ray

![Representation of origin and direction](https://602295869-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Mhms8gN-uvchlIwntnZ%2F-MhmwD8PByr4SUgzATTT%2F-MhmyvjY-hj8t328lQHs%2Fimage.png?alt=media\&token=b8f13dc5-c1c4-4da1-9d4a-0e750634dc49)

-> returns\
`metatable`

-> example\
`local RayCast2 = require(path.to.module)`\
`local ray = RayCast2.new(Vector2.new(0, 0), Vector2.new(200, 200))`

### RayCast2:Cast()

casts the ray in the given direction from the origin\
\
-> parameters \
`parent [ScreenGui]`\
`whitelist [table]`

parent - The screen gui the ray will be parented to, (only if ray.Visible is true)\
whitelist - This table should contain gui frames/imagelabels that the ray can collide with! \
\
-> returns\
`hit [Instance]`\
`position [Vector2]`\
\
hit - The gui the ray collides with\
position - The point at which the ray collides with the gui

![](https://602295869-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Mhms8gN-uvchlIwntnZ%2F-Mhn0KygXAX2dJu7NUs7%2F-Mhn0Ou_GSbsP65NUq5J%2Flol.jpg?alt=media\&token=bb95a0ab-7043-4f92-a0ef-26f86f92da7d)

-> example\
`local RayCast2 = require(path.to.module)`\
`local ray = RayCast2.new(Vector2.new(0, 0), Vector2.new(200, 200))`\
\
`local ScreenGui = path.to.screengui`\
`local Hitbox = path.to.guiframe`\
\
`local hit, pos = ray:Cast(ScreenGui, { Hitbox })`

### Ray.Visible

This property is used to determine if the ray that is created, is visible on the screen! It is set to false by default.\
\
-> example\
`local RayCast2 = require(path.to.module)`\
`local ray = RayCast2.new(Vector2.new(0, 0), Vector2.new(200, 200))`\
\
`ray.Visible = true -- when casting the ray, it will be visible on the screen`

### RayCast2:GetRayInstance()

Returns the ray guiframe IF ray.Visible is true.

-> returns \
`ray [GuiFrame]`

-> example\
`local RayCast2 = require(path.to.module)`\
`local ray = RayCast2.new(Vector2.new(0, 0), Vector2.new(200, 200))`\
\
`ray.Visible = true -- when casting the ray, it will be visible on the screen`\
\
`local ScreenGui = path.to.screengui`\
`local Hitbox = path.to.guiframe`\
\
`game:GetService("RunService").Heartbeat:Connect(function()`\
&#x20;  `local hit, pos = ray:Cast(ScreenGui, { Hitbox })`\
\
&#x20;  `local rayframe = ray:GetRayInstance()`\
&#x20;  `rayframe.BackgroundColor3 = Color3.new(1,1,1)`\
`end)`

### RayCast2:GetOrigin()

returns the origin point of the ray\
\
-> returns\
`origin [Vector2]`

-> example\
`local RayCast2 = require(path.to.module)`\
`local ray = RayCast2.new(Vector2.new(0, 0), Vector2.new(200, 200))`\
\
`print(ray:GetOrigin())`

### RayCast2:GetDirection()

returns the direction point of the ray\
\
-> returns\
`direction [Vector2]`

-> example\
`local RayCast2 = require(path.to.module)`\
`local ray = RayCast2.new(Vector2.new(0, 0), Vector2.new(200, 200))`\
\
`print(ray:GetDirection())`
