Help me fixing third person

1.What do you want to achieve?
I want to fix my third person system

  1. What is the issue?
    Character is shaking when i point camera up or down

  2. What solutions have you tried so far?
    I’ve been searching on youtube and roblox forum

Video:


Code:

local LoadedAnimation = game.Players.LocalPlayer.Character.Humanoid.Animator:LoadAnimation(script.Hold)
local equiped = false
local gyro
local char = game.Players.LocalPlayer.Character
local rootpart : Part = char:FindFirstChild("HumanoidRootPart")
script.Parent.Equipped:Connect(function()
	equiped = true
	LoadedAnimation:Play()
	gyro = Instance.new("BodyGyro", rootpart)
	gyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
	gyro.P = 15000
end)

script.Parent.Unequipped:Connect(function()
	equiped = false
	if LoadedAnimation then
		LoadedAnimation:Stop()
	end
	if gyro then
		gyro:Destroy()
	end
end)

local rs = game:GetService("RunService")

for _, index in pairs(game.Players.LocalPlayer.Character:GetChildren()) do
	if index:IsA("BasePart") and index.Name ~= "Head" and index.Name ~= "Right Arm" and index.Name ~= "Left Arm" and index.Name ~= "Torso" then
		index:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
			index.LocalTransparencyModifier = index.Transparency
		end)
		index.LocalTransparencyModifier = index.Transparency
	end
end

local mouse = game.Players.LocalPlayer:GetMouse()
local debounce = false
local damage = 80
local spread = 1
local smth = 1
local function Fire()
	local x = math.random(-spread*100,spread*100)/100
	local y = math.random(-spread*100,spread*100)/100
	local direction = (CFrame.new(script.Parent.Handle.Position, mouse.Hit.Position) * CFrame.Angles(math.rad(x), math.rad(y), 0)).LookVector
	local ray = Ray.new(script.Parent.Handle.Position,(direction).Unit * 999)
	local part, pos = workspace:FindPartOnRay(ray, game.Players.LocalPlayer.Character)
	
	if part then
		script.Parent.Shoot:FireServer(part,pos,damage)
	end
end

mouse.Button1Down:Connect(function()
	if equiped then
		for i=1, smth do
			Fire()
		end
	end
end)
rs.RenderStepped:Connect(function()
	if equiped then
		char:FindFirstChild("Humanoid").AutoRotate = false
		local x, y, z = workspace.CurrentCamera.CFrame:ToObjectSpace()
		gyro.CFrame = workspace.CurrentCamera.CFrame
	end
end)

CFrame includes the Y axis too, that means you are also setting Y axis, thus the BodyGyro tries to make your HumanoidRootPart look up or down.

Edited and refined code:

local camera = workspace.CurrentCamera
local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait() -- Make sure to wait for CharacterAdded if the player has no character yet.

char:WaitForChild("Humanoid").AutoRotate = false  -- You don't need to set this to false every RenderStepped, just set it once.

rs.RenderStepped:Connect(function()
	gyro.CFrame = CFrame.new(rootpart.Position, rootpart.Position + Vector3.new(camera.CFrame.LookVector.X, 0, camera.CFrame.LookVector.Z))
end)

(I didn’t make it adapted to your full script, you might want to adapt it yourself.)

Also you are not using this line at all dunno why it’s there:

Docs:

USE THIS FOR NEWER WORK:

Ok now It works, thank you very much. I will read all docs you send me. Thank you again.

1 Like

Don’t forget to mark as solution :smiley:

I forgot to mark a solution, sorry

1 Like