Hi there, I am trying to make a ray that will only cast a certain distance away from the player. For example, I want a ray that will come out of the players right arm and that will move wherever the player clicks, but if the click position is outside of a certain radius around the player, I want the ray to stop right at that position. If anyone knows how I could accomplish this please let me know! Thank you!
When you create the ray, the second argument is the direction and magnitude of the ray.
So to make the ray stop at a current distance we take the direction of the ray, in unit form, and multiply it by a magnitude.
Ray.new(origin, dir*magnitude)
In the case of going out of the arm, we can take the arm’s cframe’s negative topvector
local hand=char.RightHand
local ray=Ray.new(hand.Position, -hand.CFrame.TopVector * 10)
This will make the ray go from the bottom of their hand out 10 studs.
1 Like