So basically, I’m making it so that when you equip a gun your camera goes over the shoulder and this works fine and as intended, but the problem is that when I equip the gun (no matter where i’m looking) the camera just set’s it’s orientation to 0,0,0 facing the east, but after that you can freely rotate your camera as if you’re using shift lock.
here’s the code (notice how cameraanglex and cameraangley is both set to 0 by default, that’s the reason this is happening but i still dont know how to fix it)
local function ActivateOTS(gun, player)
local Offset = Vector3.new(2,2,8)
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
local camera = workspace.CurrentCamera
local cameraAngleX = 0
local cameraAngleY = 0
print()
local Character = player.Character
player.CharacterAdded:Connect(function()
cameraAngleX = 0
cameraAngleY = 0
end)
local Humanoid = Character:WaitForChild("Humanoid")
local Root = Character:WaitForChild("HumanoidRootPart")
UIS.InputChanged:Connect(function(i, gpe)
if gpe then return end
if i.UserInputType == Enum.UserInputType.MouseMovement then
cameraAngleX -= i.Delta.X
cameraAngleY = math.clamp(cameraAngleY - i.Delta.Y * 0.4, -75, 75)
end
end)
print(cameraAngleX, cameraAngleY)
RunService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function()
print(cameraAngleX, cameraAngleY)
local startCFrame = CFrame.new(Root.CFrame.Position) * CFrame.Angles(0,math.rad(cameraAngleX),0) * CFrame.Angles(math.rad(cameraAngleY),0,0)
local cameraCFrame = startCFrame:PointToWorldSpace(Offset)
local cameraFocus = startCFrame:PointToWorldSpace(Vector3.new(Offset.X, Offset.Y, -100000))
camera.CFrame = CFrame.lookAt(cameraCFrame, cameraFocus)
local lookingCFrame = CFrame.lookAt(Root.Position, camera.CFrame:PointToWorldSpace(Vector3.new(0,0,-100000)))
Root.CFrame = CFrame.fromMatrix(Root.Position, lookingCFrame.XVector, Root.CFrame.YVector)
end)
end