Hi, I currently have two functions in my script for first person visibility (normal gameplay) and headlock visibility (custom animations).
At a first glance, the code seems fine, but there is a major issue when an animation causes the characters head to rotate right or left while in headlock visibility. Essentially, the game will freak out and think the player is turning their mouse left or right, which causes their entire body to start spinning.
I’ve tried multiple solutions, and even ChatGPT, but I can’t quite figure out how to fix it. Solutions I’ve tried include:
- Setting DeltaMouseSensitivity to 0
- Locking the HRP
- Locking the camera’s rotation (don’t want that because I want the head to rotate with the anim, but not spin!
Here’s the code:
function FirstPersonVisibility()
for _,Obj in pairs(Character:GetDescendants()) do
if Obj:IsA("BasePart") and Obj.Name ~= "Head" and Obj.Name ~= "HumanoidRootPart" and Obj.Parent == Character then
Obj.LocalTransparencyModifier = 0
Obj.Transparency = 0
end
if Obj:IsA("BasePart") and Obj.Parent ~= Character then
Obj.Transparency = 0
end
end
Camera.CameraType = Enum.CameraType.Custom
Character.Humanoid.CameraOffset = Vector3.new(0,workspace.CurrentCamera.CFrame.LookVector.Y,-1)
end
function HeadLockVisibility()
for _,Limb in pairs(Character:GetChildren()) do
if Limb:IsA("BasePart") and Limb.Name ~= "Head" then
Limb.LocalTransparencyModifier = 0
end
if Limb:IsA("Accessory") then
Limb.Handle.LocalTransparencyModifier = 1
end
end
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Character.Head.CFrame * CamShakeCFOffset
end
And here’s the issue: