I’ve been a little lost in trying to create a script that will create a first person view with angle limits when a player is sitting. I’ve accomplished that to some extent, however I can’t get the angle limits to be local to the current orientation of the player’s head. For context, the player is sitting in a moving vehicle with turns(it’s an animation). I need the angle limits to be relative to the orientation of the player’s head.
The rotY = math.rad(math.clamp(math.deg(rotY), h_cfy-limit, h_cfy+limit))
line uses the head Y orientation within the clamp, so in theory it should be local.
Any help in figuring out how to achieve this would be much appreciated. I’ve included the script below. If you need any more information please let me know and I’ll be happy to provide it.
local limit=100
local cc=workspace.CurrentCamera
local rs=game:GetService("RunService")
local p=game:GetService("Players").LocalPlayer
p.CharacterAdded:wait()
local c=p.Character
local h=c:WaitForChild("Humanoid")
h.Changed:Connect(function()
if h.Sit==true then
p.CameraMode=Enum.CameraMode.LockFirstPerson
rs:BindToRenderStep("CameraLimit", Enum.RenderPriority.Camera.Value+1, function()
local hrp = h.Parent:FindFirstChild("Head")
local c_cf = cc.CFrame
local h_cfx, h_cfy, h_cfz = hrp.CFrame:ToOrientation()
local rotX, rotY, rotZ = c_cf:ToOrientation()
if h.Sit==true then
rotY = math.rad(math.clamp(math.deg(rotY), h_cfy-limit, h_cfy+limit))
cc.CFrame = CFrame.new(cc.CFrame.Position) * CFrame.Angles(rotX, rotY, rotZ)
end
end)
elseif h.Sit==false then
p.CameraMode=Enum.CameraMode.Classic
end
end)