Sorry for the confusing question, wasn’t sure how to word it haha.
Anyway, I’m working on a golf game and am trying to limit the radius in which someone can move their beam.
mouse.Move:Connect(function()
local magnitude = (humanoidRootPart.Position - mouse.Hit.p).Magnitude
if magnitude <= maximumMagnitude -- [[variable set to 20]] then
moveAttachment.WorldPosition = mouse.Hit.p
end
end)
Problem is that the beam stops moving once the cursor goes outside of the boundary. I want it to stay at 20 length but still be facing the cursor if that makes sense.
I was going to say use math.clamp() to clamp the values, but I am having trouble seeing where you could clamp the values and set it based on that. This would work if you were getting a magnitude, clamping the magnitude, and setting the position based on the magnitude. I am not quite sure how to make it work with your current setup.
Instead, in the else statement we would have to do some other calculations. First of all, we would want to find the direction vector from the player to the mouse position. Then we would use this direction vector and multiply it by your maximum magnitude and that will hopefully place the ball in the position you want it to be.
To get your direction vector, you would do:
local direction = (mouse.Hit.P - humanoidRootPart.Position).Unit
And we would take that direction vector, and multiply it by a magnitude to decide how far in the direction you want the ball placed. This should be your maximum magnitude value.
local newPosition = Vector3.new(20,20,20) * direction
And then you would set the attachment at this newPosition vector.
These calculations should be placed in the else condition, since we only want this to happen when it is at the maximum distance.