u/Complete_Crazy_2154

i wanted to make a system where player can look down and up, and waist will rotate too. Also camera will be locked to head position. But there is a bug where character is twitching and shaking

local cam = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local runs = game:GetService("RunService")
local char = plr.Character or plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local hrp = char:WaitForChild("HumanoidRootPart")
local head = char:WaitForChild("Head")
local waist = char:FindFirstChild("Waist", true)
local y = waist and waist.C0.Y or 0

local tiltEvent = game.ReplicatedStorage:WaitForChild("PlayerTiltSync")
local LERP_SPEED = 1.2
local hro = Vector3.new(0, 1.1, 0)
local co = Vector3.new(0, 0, -0.8)

runs.RenderStepped:Connect(function()
if not plr.Character and (plr.Character:GetAttribute("AnimPlaying") or plr.Character:GetAttribute("Hided")) then return end

if waist and hrp then
local relativeLook = hrp.CFrame:VectorToObjectSpace(cam.CFrame.LookVector)
local targetC0 = CFrame.new(0, y, 0) 
* CFrame.Angles(math.asin(relativeLook.Y * 0.8), -relativeLook.X, 0) 

waist.C0 = waist.C0:Lerp(targetC0, LERP_SPEED)

tiltEvent:FireServer({
WaistRotation = waist.C0
})

local targetOffset = (hrp.CFrame + hro):PointToObjectSpace(head.Position) + co
hum.CameraOffset = hum.CameraOffset:Lerp(targetOffset, 0.8)
end
end)

local function Lock(part)
if part and part:IsA("BasePart") and part.Name ~= "Head" then
part.LocalTransparencyModifier = part.Transparency
part.Changed:connect(function(property)
part.LocalTransparencyModifier = part.Transparency
end)
end
end

local ViewAccessories = false
local ViewModels = false

for i, v in pairs (char:GetChildren()) do
if v:IsA("BasePart") then
Lock(v)
elseif v:IsA("Accessory") and ViewAccessories then
if v:FindFirstChild("Handle") then
Lock(v.Handle)
end
elseif v:IsA("Model") and ViewModels then
for index, descendant in pairs (v:GetDescendants()) do
if descendant:IsA("BasePart") then
Lock(descendant)
end
end
end
end
reddit.com
u/Complete_Crazy_2154 — 13 days ago