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

Can someone explain the Ray Methods? How do you use it to find a part?

Asked by 6 years ago

I'm planning on making tools for a game, but it will require using rays and it is very new to me. I read about Rays on the Wiki but the Methods didn't make a lot of sense to me. Can anyone help me with the methods and especially what ClosestPoint is? Also maybe an example script/explanation on how to use it to print the first part it passes through or something because I'm also very confused on how to do that. Thank you!

1 answer

Log in to vote
1
Answered by 6 years ago

If you are making a gun or laser or something, you don't need closest point. To make a ray, use Ray.new like so:

ray = Ray.new(origin, direction)

Example:

--studDistance is how far the ray should go
studDistance = 500
ray = Ray.new(Tool.Handle.CFrame.p, (mouse.Hit.p - tool.Handle.CFrame.p).unit * studDistance)

what that does, is it makes a ray with the origin of the tools handle, and takes the mouse click position, and minuses that by the tool handle to give you a vector3 direction, which we do .unit on and times it by how far you want it to go.

A great article on raycasting guns is in this link: http://wiki.roblox.com/index.php?title=Making_a_ray-casting_laser_gun

0
Why use CFrame instead of position? Is there a difference? Adv3rtizement 101 — 6y
0
From the wiki, it doesn't look like it ronitrocket 120 — 6y
0
CFrame can include the position as well as the rotation Programical 653 — 6y
Ad

Answer this question