Hello! So, I’d like to cap the player’s mouse position (per se, 100 studs from the player’s character).
How would I do that?
Hello! So, I’d like to cap the player’s mouse position (per se, 100 studs from the player’s character).
How would I do that?
You should get the mouse from the player and if you want to get where it is, you say “mouse.hit.p” It works for a lot of others, I have personally never tried it, but I hope this helps.
That doesn’t answer my question. I’d like to cap the mouse’s position, not get it.
Do you mean check it’s distance from the player?
If the mouse is too far away from the player, the position caps.
You can check the distance by using ((player root part variable here).Position - mouse.hit.p).magnitude
I am sorry if it does not work.
This is going to be really complicated. Why do you need it? I’m sure there is a better way.
It really isn’t, I just got helped on scripting helpers.
local pos = mouse
local hrpPos = plr.Character.HumanoidRootPart.Position
local diff = pos - hrpPos
if diff.magnitude > 100 then
pos = hrpPos + diff.Unit * 100
end
local Player = game:GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local function isWithinDistance(distance)
if (not Mouse.Hit) then
return
end
return Player:DistanceFromCharacter(Mouse.Hit.Position) <= distance
end
if (isWithinDistance(100)) then
print("Allowed")
else
print("Rejected")
end