I’m making a tool that can essentially grab a player and move them based on mouse position (using the unitray property). It works fine, until you zoom out since then the player would also be really far out. Found a few results, but none of them really fit my current situation (as far as I know, I could just be being really dumb though lol).
https://gyazo.com/aba37daa4857d2b68f02896882598da7
local Align: AlignPosition = HRP:FindFirstChild("RootAttachment"):FindFirstChild("Pos") -- align position inside target's HRP
local Pos = MouseRay.Origin + (MouseRay.Direction * 20)
local PlrHRP: BasePart = plr.Character:FindFirstChild("HumanoidRootPart") -- player's HRP
if ((MouseRay.Origin + MouseRay.Direction) - PlrHRP.Position).Magnitude > 20 then
-- dont know what to do here
end
Align.Position = Pos
Unsure what MouseRay is (or why you are using the Direction vector from it) so my answer may require some modification on your part, but should give you the general idea.
In order to force the shape to be within a certain radius of the player’s position, you would get the unit vector of the difference between the origin and the selected position (possibly playerPos - MousePos) then multiply that by whatever your radius is.
e.g.
if ((MouseRay.Origin + MouseRay.Direction) - PlrHRP.Position).Magnitude > 20 then
local Unit = (MouseRay.Origin + MouseRay.Direction) - PlrHRP.Position).Unit
Align.Position = PlrHRP.Position + (Unit * 20) -- 20 is the radius
else
Align.Position = Pos
end
(If it’s not clear enough which values I mean, let me know and I can try to explain it differently)
Ahh, gotcha. Ill see if it works.
MouseRay is just Mouse.UnitRay, but passed into the server. I used it since it accurately like, put the player on the mouse position. Sorry for the confusion.
Its close (since it does limit the reach), but it kind of gets rubber banded back. Even to the sides, it rubber bands to the back of the humanoid root part. I think what I may try doing is instead of using the UnitRay of the mouse, ill just use Mouse.Hit (although getting magnitude for that accurately can be annoying)
https://gyazo.com/7fef2544654cb6a51e674a25af4ee716
Ended up having to make it not be accurate, but its much better than being able to send someone far out. Thank you Seargent for the advice though, ended up changing it slightly to instead use the lookvector of the mouse instead of Mouse.Hit (the direction was being skewed since if you were aiming at nothing, the CFrame would be like a thousand studs away)
local Align = HRP:FindFirstChild("RootAttachment"):FindFirstChild("Pos") -- target's HRP
local PlrHRP: BasePart = plr.Character:FindFirstChild("HumanoidRootPart") -- player's HRP
Align.Position = PlrHRP.Position + (MousePos.LookVector * 20)