What is the most effective way of Ray Casting? Do any of you have any tip on Ray Casting?
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 )