Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How does FindPartOnRay work?

Asked by
Mystdar 352 Moderation Voter
8 years ago

So on the wiki it says it triggers when a part intercepts your ray, but can someone, using code, explain how I would execute this as;

local part, endPoint = Workspace:FindPartOnRay(ray)

doesn't make sense to me.

And how will I use it for a function that fires on this event firing (it being intercepted).

1 answer

Log in to vote
1
Answered by 8 years ago

Workspace:FindPartOnRay(ray) does as it's told (Finds a BasePart that is colliding with the ray closest to the ray's origin, like a laser hitting a wall).

In your case, part is the BasePart that the ray has collided with, and endpoint is the location of the collision, a Vetcor3.

You can use it for a function like this:

function YourFunction()
--stuff
end

ray = Ray.new() --Your ray
local part, endpoint = Workspace:FindPartOnRay(ray)
if part then YourFunction() end

Workspace:FindPartOnRay(ray) isn't an event, so you'd have to run the function when you want to check for intersecting parts.

0
Thanks! Mystdar 352 — 8y
Ad

Answer this question