Hey there! I recently thought to implement an over the shoulder camera system for my game.
What is the problem?
Well, the problem lies in the camera not rotating on the Y axis. The camera does move on the x axis but I want to move it to the Y axis too.
What have you tried so far?
Well, I have tried the following in a local script. (I do not get any errors):
local UIS = game:GetService("UserInputService")
local Character = script.Parent
local Camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")
local Root = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")
local BodyGyro = Instance.new("BodyGyro")
local CameraXSensitivity = 0.5
local IsMouseLocked = true
Humanoid.AutoRotate = false
BodyGyro.MaxTorque = Vector3.new(0, 4e5, 0)
BodyGyro.P = 4e5
BodyGyro.Parent = Root
UIS.InputBegan:Connect(function(input)
if (input.UserInputType == Enum.UserInputType.Keyboard) then
if (input.KeyCode == Enum.KeyCode.LeftAlt) then
print("Unlocked")
IsMouseLocked = not IsMouseLocked
end
end
end)
UIS.InputChanged:Connect(function(input)
if (input.UserInputType == Enum.UserInputType.MouseMovement) then
local xDelta = input.Delta.X
local DegreeChange = math.rad(xDelta * CameraXSensitivity)
BodyGyro.CFrame = BodyGyro.CFrame * CFrame.fromAxisAngle(Vector3.new(0, 1, 0), -DegreeChange) -- This is the part which probably needs changing.
end
end)
RunService:BindToRenderStep("otsCamera", 201, function()
local lookAt = (Root.CFrame * CFrame.new(0, 0, -20)).Position
local CamStartPos = (Root.CFrame * CFrame.new(4, 4, 10)).Position
if IsMouseLocked then
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
else
UIS.MouseBehavior = Enum.MouseBehavior.Default
end
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CFrame.new(CamStartPos, lookAt)
end)
Thanks for any help.
If you do not understand any part of the question please comment.
