Hello, currently Im making a framework system. when starting to walk ever since I changed it from an animation to Cframes its been glitching. It only happens when I stop and walk again.
RunService.RenderStepped:Connect(function()
local currentCameraRotation = workspace.CurrentCamera.CFrame
local deltaRotation = currentCameraRotation:ToObjectSpace(lastCameraRotation)
local _, deltaY, deltaZ = deltaRotation:ToOrientation()
local targetSwayX = math.clamp(deltaY * swayIntensity, -0.05, 0.05)
local targetSwayY = math.clamp(deltaZ * swayIntensity, -0.05, 0.05)
local targetSway = CFrame.new(targetSwayX, targetSwayY, 0) * CFrame.Angles(0, -targetSwayX * 0.5, targetSwayY * 0.5)
swayAmount = swayAmount:Lerp(targetSway, swaySmoothing)
lastCameraRotation = currentCameraRotation
local targetBob = CFrame.new()
if character and character.Humanoid then
local walkVector = character.Humanoid.MoveDirection
local isMoving = walkVector.Magnitude > 0
if isMoving and not Manager.isAimed then
if not wasMoving then
local cycleRemainder = bobCycle % (math.pi * 2)
if cycleRemainder > math.pi then
bobCycle = math.pi * 2
else
bobCycle = 0
end
end
bobCycle = bobCycle + (RunService.RenderStepped:Wait() * bobSpeed)
local bobX = math.sin(bobCycle) * bobIntensity
local bobY = math.abs(math.sin(bobCycle * 2)) * bobIntensity
local bobZ = math.cos(bobCycle * 0.5) * bobIntensity * 0.5
local bobRotX = math.sin(bobCycle * 1.5) * 0.02
local bobRotY = math.sin(bobCycle) * 0.015
local bobRotZ = math.cos(bobCycle * 1.2) * 0.01
targetBob = CFrame.new(bobX, bobY, bobZ) * CFrame.Angles(bobRotX, bobRotY, bobRotZ)
else
bobCycle = bobCycle * 0.9
end
wasMoving = isMoving
end
bobAmount = bobAmount:Lerp(targetBob, bobSmoothing)
local targetTransform = aimCF * swayAmount * bobAmount
combinedTransform = combinedTransform:Lerp(targetTransform, transformSmoothing)
for i, v in pairs(workspace.Camera:GetChildren()) do
if v:IsA("Model") then
v:SetPrimaryPartCFrame(workspace.CurrentCamera.CFrame * combinedTransform)
end
end
if Framework and Framework.AimPart then
if Manager.isAimed then
local offset = Framework.AimPart.CFrame:ToObjectSpace(Framework.PrimaryPart.CFrame)
aimCF = aimCF:Lerp(offset, 0.1)
else
aimCF = aimCF:Lerp(CFrame.new(), 0.1)
end
end
end)
CFrame part of the script
local aimCF = CFrame.new()
local Framework = nil
local currentGunModule = nil
local lastCameraRotation = workspace.CurrentCamera.CFrame
local swayAmount = CFrame.new()
local swayIntensity = 0.2
local swaySmoothing = 0.1
local bobAmount = CFrame.new()
local bobCycle = 0
local bobSpeed = 8
local bobIntensity = 0.03
local bobSmoothing = 0.15
local wasMoving = false
local combinedTransform = CFrame.new()
local transformSmoothing = 0.2
variables
video of the visual glitch