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!
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