I'm trying to make a custom camera that is somewhat like shiftlock but in the middle. The position of the camera is correct but it doesn't rotate when moving the mouse. Is there anything I'm doing wrong?
local Players = game:GetService('Players')
local UserInputService = game:GetService('UserInputService')
local ContextActionService = game:GetService('ContextActionService')
local RunService = game:GetService('RunService')
local Camera = workspace.CurrentCamera
local Focus = Vector3.new (0,2,2)
local Zoom = 0
local Player = Players.LocalPlayer
Player.CharacterAdded:connect(function(Character)
Camera.CameraSubject = Character:WaitForChild('Humanoid', math.huge)
Character.Humanoid.AutoRotate = false
local CamAngleY = 0
local function MouseMove(ActionName, InputState, InputObject)
if InputState == Enum.UserInputState.Change then
CamAngleY = math.clamp(CamAngleY - InputObject.Delta.Y*10, -75, 75)
Character.HumanoidRootPart.CFrame = Character.HumanoidRootPart.CFrame * CFrame.Angles(0,math.rad(-InputObject.Delta.X*10),0)
end
end
ContextActionService:BindAction("MouseMove",MouseMove,false,Enum.UserInputType.MouseMovement)
RunService.RenderStepped:connect(function()
if Camera.CameraType ~= Enum.CameraType.Scriptable then
Camera.CameraType = Enum.CameraType.Scriptable
end
local FocusPosition
FocusPosition = Character.HumanoidRootPart.CFrame * CFrame.new(Focus) * CFrame.Angles(math.rad(CamAngleY),0,0)
Camera.CFrame = FocusPosition * CFrame.new(Vector3.new(0,0,4-Zoom))
end)
end)
function MouseLock(ActionName, InputState, InputObject)
if InputState == Enum.UserInputState.Begin then
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
ContextActionService:UnbindAction(ActionName)
end
end
ContextActionService:BindAction("MouseLock",MouseLock,false,Enum.UserInputType.MouseButton1)
