Here's my code:
1 | local rayOrigin = humrp.Position; |
2 | local rayDirection = direction.p; |
3 |
4 | local rayCast = Ray.new(rayOrigin, (rayDirection-rayOrigin).unit* 20 ); |
5 | 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
1 | 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