Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help with Torso/Head follow mouse script?

Asked by
ax_gold 360 Moderation Voter
6 years ago

I made a simple, 15-line script that lets your character's head and UpperTorso follow their mouse. The problem is, whenever I turn the camera to face an X angle (left and right), it glitches. Put the script below in a localscript in startergui and see for yourself. It works perfect when I face a Z angle (forward and behind). Does anyone know what I'm doing wrong and how to fix it?

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:wait() ; Character = Player.Character
local Torso = Character:WaitForChild("UpperTorso")
local Neck = Character:WaitForChild("Head"):WaitForChild("Neck")
local Up = Character:WaitForChild("UpperTorso"):WaitForChild("Waist")
local Humanoid = Character:WaitForChild("Humanoid")
local Mouse = Player:GetMouse()

local NeckC0 = Neck.C0
local NeckC1 = Neck.C1

Mouse.Move:connect(function()
    Neck.C0 = NeckC0 * CFrame.Angles(math.asin(Mouse.Origin.lookVector.Y), 0, 0)
    Up.C0 = (NeckC0 - Vector3.new(0,0.3,0)) * CFrame.Angles(math.asin((Mouse.Origin.lookVector.Y)), math.sin(Mouse.Origin.lookVector.X/math.sin(workspace.CurrentCamera.CFrame:inverse().lookVector.Y * -1)/7) , 0)
end)

Answer this question