First post, I want to make a movement system which flings the player in the direction they click. I want the force to be just anough for the player to reach the part, and not come short or slam into it.
If theres a better way to do this which im missing please tell me
example code, localscript in starter character folder
local plr = game.Players.LocalPlayer
local char = plr.Character
local mouse = plr:GetMouse()
mouse.Button1Down:Connect(function()
if (char.HumanoidRootPart.Position - mouse.Hit.Position).Magnitude < 100 then
local position = mouse.hit.p
local fling = Instance.new("LinearVelocity")
fling.Attachment0 = char.HumanoidRootPart.RootAttachment
local mouseangle = CFrame.lookAt(char.HumanoidRootPart.Position, mouse.Hit.Position)
fling.VectorVelocity = mouseangle.LookVector * 100
fling.Parent = char
fling.MaxForce = math.huge
wait(0.1) --I would not like to have the velocity running until I hit the wall, as it stops all other motion which would mess up some other stuff
fling:Destroy()
end
end)
thanks
edit: heres what it looks like in studio