What is the most effective way of Ray Casting? Do any of you have any tip on Ray Casting?
✓ ANSWER ACCEPTED
Need help in Ray Castings?
1 answer
✓ Accepted answer
You should definitely use Roblox's raycasting system. According to the wiki, it's 105 times faster than the most efficient known user-made raycasting algorithm. This is because Roblox could code it in C++.
You use Ray.new to create a new ray. You will then supply the origin and the direction of the ray as arguments.
local ray = Ray.new( Vector3.new(0, 0, 0,), Vector3.new(0, 50, 0) ) --Makes a ray shooting upwards from 0,0,0 for 50 studs.
You can then use the FindPartOnRay method of workspace to see if your ray hit something. FindPartOnRay returns a tuple, including the part that the ray hit and the position that it hit at. If it didn't hit anything, hit and position will be nil and the end of the ray, respectively.
hit, position = workspace:FindPartOnRay(ray)
print( hit, position )
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
using CFrame. look Vector.
game.Workspace:FindPartOnRay()... Or something like that