I am working on an Over-The-Shoulder Camera system.
What is the problem you are facing?
Well, I have my Over-The-Shoulder Camera script ready but the problem is that I can only rotate the character on the X-Axis. I want to be able to rotate it on the Y-Axis too. As you can see below, I am only able to rotate my character on the X-axis.
https://gyazo.com/3a93e007c2654a9133011f63ecd64df7
This is my Local Script placed inside the StarterPlayer → StarterCharacterScripts:
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) -- This could probably be the problem since we are getting the degree changed for the x value only but I can't seem to find a way to get the y axis and place it in DegreeChange.
BodyGyro.CFrame = BodyGyro.CFrame * CFrame.fromAxisAngle(Vector3.new(0, 1, 0), -DegreeChange)
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)
In simple words, I also want to be able to look up-down. Not only right-left.
Thanks for any help