Help with Torso/Head follow mouse script?
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?
01 | local Player = game.Players.LocalPlayer |
02 | local Character = Player.Character or Player.CharacterAdded:wait() ; Character = Player.Character |
03 | local Torso = Character:WaitForChild( "UpperTorso" ) |
04 | local Neck = Character:WaitForChild( "Head" ):WaitForChild( "Neck" ) |
05 | local Up = Character:WaitForChild( "UpperTorso" ):WaitForChild( "Waist" ) |
06 | local Humanoid = Character:WaitForChild( "Humanoid" ) |
07 | local Mouse = Player:GetMouse() |
12 | Mouse.Move:connect( function () |
13 | Neck.C 0 = NeckC 0 * CFrame.Angles(math.asin(Mouse.Origin.lookVector.Y), 0 , 0 ) |
14 | Up.C 0 = (NeckC 0 - Vector 3. 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 ) |