Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[ Head Follow Mouse/Camera ]-- -Script By lakastanmi ENJOY! <3
- --[ Services ]:
- local RunSrv = game:GetService("RunService");
- local Wrks = game:GetService("Workspace");
- local Plrs = game:GetService("Players");
- --[ Pre-Funcs ]:
- local Ang = CFrame.Angles; --[ Storing these as variables so I dont have to type them out. ]
- local aSin = math.asin;
- local aTan = math.atan;
- --[ Constants ]:
- local Cam = Wrks.CurrentCamera;
- local Plr = Plrs.LocalPlayer;
- local Mouse = Plr:GetMouse();
- local Body = Wrks:WaitForChild(Plr.Name);
- local Head = Body:WaitForChild("Head");
- local Hum = Body:WaitForChild("Humanoid");
- local Core = Body:WaitForChild("HumanoidRootPart");
- local IsR6 = (Hum.RigType.Value==0); --[ Checking if the player is using the new Rig or the original. ]
- local Trso = (IsR6 and Body:WaitForChild("Torso")) or Body:WaitForChild("UpperTorso");
- local Neck = (IsR6 and Trso:WaitForChild("Neck")) or Head:WaitForChild("Neck"); --[ Once we know the Rig, we know what to find. ]
- local MseGuide = false; --[ Useful with tools if true; camera tracking runs smoother however. ]
- local Fctor = 1; --[ 0: Negates tracking, 1: Relatively normal tracking, 2: Looks a little weird, just sayin'. ]
- local OrgnC0 = Neck.C0; --[ Get the base C0 to manipulate off of. ]
- --[ Setup ]:
- Neck.MaxVelocity = 1/3
- --[ Activation ]:
- coroutine.resume(coroutine.create(function()
- while RunSrv.RenderStepped:wait() and Hum:GetState().Value~=15 do --[ Adding wait() here is the same as adding wait() later. ]
- local CamCF = Cam.CoordinateFrame
- --local MsePos = Mouse.Origin.p --[ Might do something with this in a future update... ]
- if ((IsR6 and Body["Torso"]) or Body["UpperTorso"])~=nil and Body["Head"]~=nil then --[ Check for the Torso and Head... ]
- local TrsoLV = Trso.CFrame.lookVector
- local HdPos = Head.CFrame.p
- if ((IsR6 and Trso["Neck"]) or Head["Neck"])~=nil then --[ Make sure the Neck still exists. ]
- if Cam.CameraSubject:IsDescendantOf(Body) or Cam.CameraSubject:IsDescendantOf(Plr) then
- local Dist = nil;
- local Diff = nil;
- if not MseGuide then --[ If not tracking the Mouse then get the Camera. ]
- Dist = (Head.CFrame.p-CamCF.p).magnitude
- Diff = Head.CFrame.Y-CamCF.Y
- if not IsR6 then --[ R6 and R15 Neck rotation C0s are different; R15: X axis inverted and Z is now the Y. ]
- Neck.C0 = OrgnC0*Ang((aSin(Diff/Dist)*Fctor), -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y, 0)
- else --[ R15s actually have the properly oriented Neck CFrame. ]
- Neck.C0 = OrgnC0*Ang(-(aSin(Diff/Dist)*Fctor), 0, -(((HdPos-CamCF.p).Unit):Cross(TrsoLV)).Y)
- end
- else
- local _, Point = Wrks:FindPartOnRay(Ray.new(Head.CFrame.p, Mouse.Hit.lookVector), Wrks, false, true)
- Dist = (Head.CFrame.p-Point).magnitude
- Diff = Head.CFrame.Y-Point.Y
- if not IsR6 then
- Neck.C0 = OrgnC0*Ang(-(aTan(Diff/Dist)*Fctor), (((HdPos-Point).Unit):Cross(TrsoLV)).Y*Fctor, 0)
- else
- Neck.C0 = OrgnC0*Ang((aTan(Diff/Dist)*Fctor), 0, (((HdPos-Point).Unit):Cross(TrsoLV)).Y*Fctor)
- end
- end
- end
- end
- end
- end
- end))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement