Telekenisis How to control the length from players character to the mouse

Hi My goal here is to obtain a good working telekenisis tool. But i have one issue, i want to make the person that the player is controlling not to go far away far away from the player that is controlling him. Is there any way i can archive this?
robloxapp-20200928-1909548.wmv (4.7 MB)
In my script, i am using a bodymover(Body Position) to set the position of the victim to the mouse position But for example: if i look up, the players goes all the way to the end of the world because of the mouse position.

while seeing some code would be nice, you can simply use .Magnitude to get the distance, for example:

if (PlayerPos - MousePos).Magnitude >= SomeValue then
    StopHolding()
end

Yea that makes it so that the victim stops moving if he passes the max magnitude even though i am still holding the key that controls the victim. What i want is to make the victim to be in the mouse’s position but near the character, not far away

you can use a custom implementation of the mouse with raycasting, camera:viewportpointtoray, and userinputservice’s envents.
To get the mouse’s position we use InputChanged
next, we use ScreenPointToRay
Then we update it.
This is an example using a part in workspace:

function MovePlayerToPosition(Position)
	workspace.Part.Position = Position
end
local MaxDist = 50
local ignore = RaycastParams.new()
ignore.FilterType = Enum.RaycastFilterType.Blacklist
ignore.FilterDescendantsInstances = {workspace.Part}
game:GetService("UserInputService").InputChanged:Connect(function(Input, gpe)
	if Input.UserInputType == Enum.UserInputType.MouseMovement then
		local UnitRay = workspace.Camera:ScreenPointToRay(Input.Position.X, Input.Position.Y)
		local Result = workspace:Raycast(UnitRay.Origin, UnitRay.Direction * MaxDist, ignore)
		if Result then
			MovePlayerToPosition(Result.Position)
		else
			MovePlayerToPosition(UnitRay.Origin + (UnitRay.Direction * MaxDist))
		end
	end
end)
2 Likes

Wow! Thanks!, i still havn’t learnt Ray, i dont know a better way to but anyway
it worked :slight_smile: