So I am currently making clicks visible in my game, here is a gif of what I mean: https://gyazo.com/a93b9f55c656a069aa2553fdddac7b9d
If you notice at the end of the gif, the cursor just goes infinitely in one direction, and disappears on the skybox. Instead of just limiting the distance it can travel, I want it to work like "Lumber Tycoon 2" where it has some sort of sphere (maybe even phyics if it is simple, I doubt though) of where the visual/cursor can go.
I tried putting a hollow sphere around the player and the issue is that the visual goes inside or on top of it, so that isn't going to work.
Here is my code:
player = game.Players.LocalPlayer
playerMouse = player:GetMouse()
playerMouse.Button1Down:connect(function()
if workspace["Player Cursors"]:FindFirstChild(player.Name .. " cursor") then
workspace["Player Cursors"][player.Name .. " cursor"]:Destroy()
end
visualCursor = game.ReplicatedStorage["Visual Cursor"]:Clone()
visualCursor.Name = player.Name .. " cursor"
visualCursor.Parent = workspace["Player Cursors"]
playerMouse.TargetFilter = visualCursor
game:GetService("RunService").RenderStepped:connect(function()
visualCursor.Position = playerMouse.Hit.p
end)
end)
playerMouse.Button1Up:connect(function()
visualCursor:Destroy()
end)
visualCursor is just a little white sphere I cloned from ReplicatedStorage.
Any suggestions how I would go about this?

3 comments
Your math is right, even I can understand this stuff ;)
Can I please get an explanation, I understand the variables, but what about line 15 and how it works together?
Player position offset by a vector with a maximum length of 20 in the direction of the cursor.