Here's my code:
local rayOrigin = humrp.Position; local rayDirection = direction.p; local rayCast = Ray.new(rayOrigin, (rayDirection-rayOrigin).unit*20); local part = workspace:FindPartOnRay(rayCast, character, false, true);
Where "rayOrigin" is the player's HumanoidRootPart Position and the rayDirection is "mouse.Hit.p"
I assumed the "unit*20" would set the range of the raycast to 20 but I guess I was very wrong haha. The raycast fires a beam that can go as far as it would like. How would I set the range of the ray to 30 studs?
Any help is greatly appreciated! Thanks!
You used unit on the wrong part
local rayCast = Ray.new(rayOrigin, (rayDirection-rayOrigin)).Unit*20
Is what you're looking for, it didn't error before because you can use .unit on a Vector3 to change it's length to 1, in this case (rayDirection-rayOrigin) was that Vector3