Limiting the distance of mouse position


I am working on something right now, and I had just now been noticing that my script is a slight inaccurate to the true mouse position.


    --# MOUSE
	local distanceFromMouse = (RightHand.Position - mousePosition).Magnitude

	local a ="Part", workspace)
	a.Anchored = true
	if (distanceFromMouse <= abilitySettings['distance_limit']) then
		a.Position = mousePosition
		a.Position = RightHand.Position + ((mousePosition - RightHand.Position).Unit) * abilitySettings['distance_limit']

I am hoping that someone has a solution to this, wanting it to be as accurate as possible. I am trying to make it so a part spawns where the mouse position is, but to keep it in a specific radius of the character.

Here is a better look,

When its close to you, in that range, it looks perfect. When it goes to setting the position if its outside of the radius, it goes inaccurate to the mouse point.

Use the position from the camera instead of the right hand

Camera can be accessed in a local script with workspace.CurrentCamera

1 Like

You are a lifesaver!!! Thank you!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.