Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to set a limit on how far a ray cast can go?

so this is the raycast

local ray = Ray.new(char:FindFirstChildOfClass("Tool").tool.barrel,pos)

so how would i change this so it only goes one stud?

1 answer

✓ Accepted answer

the Ray.new constructor takes 2 arguments, the starting position, and the Direction where the ray should go.. the magnitude of the direction vector determines how far the ray will go..

therefore, if you wanted a ray to go 300 studs, you'd have to do direction.Unit * 300

if you have the starting position, and an end position, you can get the direction by doing direction = endPosition - startingPosition.. learn more here

NOTE THIS: the constructor doesn't take a starting position, and an end position

This discussion is preserved as it was. New answers, comments, and votes are closed.