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
7 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?

01local Player = game.Players.LocalPlayer
02local Character = Player.Character or Player.CharacterAdded:wait() ; Character = Player.Character
03local Torso = Character:WaitForChild("UpperTorso")
04local Neck = Character:WaitForChild("Head"):WaitForChild("Neck")
05local Up = Character:WaitForChild("UpperTorso"):WaitForChild("Waist")
06local Humanoid = Character:WaitForChild("Humanoid")
07local Mouse = Player:GetMouse()
08 
09local NeckC0 = Neck.C0
10local NeckC1 = Neck.C1
11 
12Mouse.Move:connect(function()
13    Neck.C0 = NeckC0 * CFrame.Angles(math.asin(Mouse.Origin.lookVector.Y), 0, 0)
14    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)
15end)

Answer this question