I’ve been trying to make this Player Mouse w/ waist movement work for hours now but can’t seem to figure it out. It would be really appreciated if someone would help me figure out what I’m doing wrong and what should I do to fix it. I’m sure this would be useful for others as well.
--//Variables
local UserInputService = game:GetService("UserInputService")
local Plr = game:GetService("Players").LocalPlayer
local xAngle = 0
local yAngle = 0
--//Functions
local function projectScreenPointToWorldGeometry(x, y)
local ray = workspace.CurrentCamera:ScreenPointToRay(x, y)
local _, pos = workspace:FindPartOnRay(Ray.new(ray.Origin, ray.Direction*5000))
return pos
end
local function limitAngles(CF, X, Y)
X = math.rad(X); Y = math.rad(Y)
local x, y = CF:toEulerAnglesXYZ()
return CFrame.new(CF.p) * CFrame.Angles(
math.clamp(x, 0, X),
math.clamp(y, -Y, Y),
0
)
end
game:GetService("RunService"):BindToRenderStep("CameraMove",Enum.RenderPriority.Camera.Value-1,function()
local rootPart = Plr.Character:FindFirstChild("HumanoidRootPart")
if Plr.Character and rootPart then
local RotationOffset = (Plr.Character.PrimaryPart.CFrame-
Plr.Character.PrimaryPart.CFrame.p):inverse()
local Pos = projectScreenPointToWorldGeometry(xAngle, yAngle) --// Pos as in the Target position of where I would want the Waist to face
local RealPos = -(Plr.Character.PrimaryPart.CFrame.p - Pos).unit * 5000
local TargetCFrame = RotationOffset * CFrame.new(Vector3.new(0, 0, 0), RealPos)
Waist.Transform = limitAngles(TargetCFrame, 0, 15)
end)
--// Mouse movement recorder
UserInputService.InputChanged:Connect(function(Input, gameProcessed)
if Input.UserInputType == Enum.UserInputType.MouseMovement then
xAngle = Input.Delta.X
yAngle = Input.Delta.Y
end
end)