Shoulder camera glitches and isn't smooth

You can write your topic however you want, but you need to answer these questions:

  1. **What do you want to achieve?
    I am attempting to make a shoulder camera that moves when the mouse movement is detected

  2. **What is the issue?
    It stops moving on the x axis if I contentiously move it around trying to do a circle, and the y axis doesnt work properly, I just have it set to a random position on the map to start off with but I am not sure how I should go about it.

local Game = game
local Workspace = workspace
local RunService = Game:GetService("RunService")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Camera = Workspace.CurrentCamera
local offset = Vector3.new()
local rootPart = Character:WaitForChild("UpperTorso")
local UIS = game:GetService("UserInputService")
local Mouse = Player:GetMouse()
Mouse.TargetFilter = Character

local MouseTurnSpeedXaxis = 10
local MouseTurnSpeedYaxis = 5



local Mouse_Turn_Speed_X_axis_RIGHT_ForScript = MouseTurnSpeedXaxis * -1
local Mouse_Turn_Speed_X_axis_Left_ForScript = MouseTurnSpeedXaxis 


local Mouse_Turn_Speed_Y_axis_UP_ForScript = MouseTurnSpeedYaxis * -1
local Mouse_Turn_Speed_Y_axis_DOWN_ForScript = MouseTurnSpeedYaxis 


--local PointPos = workspace.aiming.Position
local PointPos =  Vector3.new(0,0,0)

--UIS.MouseBehavior = Enum.MouseBehavior.LockCent




local players = game:GetService("Players")
local player = players.LocalPlayer
local mouse = player:GetMouse()

local lastMouseX, lastMouseY = mouse.X, mouse.Y

local function mouseMoved(actionName, inputState, inputObject)	
	if inputObject.Delta.X > 0 then
		warn("right")
		PointPos = PointPos - Vector3.new(Mouse_Turn_Speed_X_axis_RIGHT_ForScript,0,0)
		
	elseif inputObject.Delta.X < 0 then
		warn("left")
		PointPos = PointPos - Vector3.new(Mouse_Turn_Speed_X_axis_Left_ForScript,0,0)

	elseif inputObject.Delta.Y > 0 then
		warn("Down")
		PointPos = PointPos - Vector3.new(0,Mouse_Turn_Speed_Y_axis_DOWN_ForScript,0)

	elseif inputObject.Delta.Y < 0 then
		warn("Up")
		PointPos = PointPos - Vector3.new(0,Mouse_Turn_Speed_Y_axis_UP_ForScript,0)

	end
end
game:GetService("ContextActionService"):BindAction("MouseMoved", mouseMoved, false, Enum.UserInputType.MouseMovement)




local function OnRenderStep()
	local MousePosition = Mouse.Hit.Position
	UIS.MouseBehavior = Enum.MouseBehavior.LockCenter

	if workspace.CurrentCamera.CameraType ~= "Scriptable" then
		workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
	end
	local char =  Character
	local charCF = char:GetPrimaryPartCFrame()
	local direction = ((PointPos - charCF.Position) * Vector3.new(1,0,1)) + Vector3.new(0, charCF.Position.Y,0)
	local newCF = CFrame.lookAt(charCF.Position, charCF.Position + direction, Vector3.new(0,1,0))
	char:SetPrimaryPartCFrame(newCF)
	Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CFrame.new(Character:GetPivot() *Vector3.new(2, 4, 13),PointPos)   
--	Camera.CFrame = CFrame.Angles(Character:GetPivot() *Vector3.new(2, 4, 13),PointPos.Y,0)   
	



end


RunService.RenderStepped:Connect(OnRenderStep)



Guidence as to what I am doing wrong would help a lot

External Media

Sounds like Gimbal Lock.

local uis = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
humanoid.AutoRotate = false
local hrp = char:WaitForChild("HumanoidRootPart")
local x = 0
local y = 0
local offset = Vector3.new(3, 3, 10)


uis.InputChanged:Connect(function(input, processed)
	
	if processed then return end
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		x = x - input.Delta.X
		y = math.clamp(y - input.Delta.Y*0.4, -75, 75)
		local startCFrame = CFrame.new((hrp.CFrame.Position)) * CFrame.Angles(0, math.rad(x), 0) * CFrame.Angles(math.rad(y), 0, 0)
		local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, offset.Z))
		local cameraDirection = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, -10000))
		
		local char =  char
		local charCF = char:GetPrimaryPartCFrame()
		local direction = ((cameraDirection.Position - charCF.Position) * Vector3.new(1,0,1)) + Vector3.new(0, charCF.Position.Y,0)
		local newCF = CFrame.lookAt(charCF.Position, charCF.Position + direction, Vector3.new(0,1,0))
		char:SetPrimaryPartCFrame(newCF)

			end
end)


game:GetService("RunService").RenderStepped:Connect(function()
	
	uis.MouseBehavior = Enum.MouseBehavior.LockCenter
	local startCFrame = CFrame.new((hrp.CFrame.Position)) * CFrame.Angles(0, math.rad(x), 0) * CFrame.Angles(math.rad(y), 0, 0)
	local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, offset.Z))
	local cameraDirection = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, -10000))
	camera.CFrame = CFrame.new(cameraCFrame.Position, cameraDirection.Position)
end)```

Found a working method

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.