Haven’t read that sorry, you have to add this line at the very top of the script:
local spring = require(ReplicatedStorage.spring)
self.springs.walkCycle = spring.create();
self.springs.sway = spring.create()
Or maybe you wanted a de-OOP-ed version of the sway implementation
local camera=workspace.CurrentCamera
local viewmodel_camera= --Enter camera part of your viewmodel
local rootPart= --Enter the primary part of your viewmodel
local spring = require(ReplicatedStorage.spring)
springs_walkCycle = spring.create()
springs_sway = spring.create()
local function getBobbing(addition, speed, modifier)
return math.sin(tick()*addition*speed)*modifier
end
function update(deltaTime)
local animatorCFrameDifference = lastReceiverRelativity or CFrame.new() *viewmodel_camera.CFrame:ToObjectSpace(rootPart.CFrame):Inverse()
local x,y,z = animatorCFrameDifference:ToOrientation()
workspace.Camera.CFrame = workspace.Camera.CFrame * CFrame.Angles(x, y, z)
lastReceiverRelativity = viewmodel_camera.CFrame:ToObjectSpace(rootPart.CFrame)
local velocity = character.HumanoidRootPart.Velocity
local finalOffset = equipOffset
-- Let's get some mouse movement!
local mouseDelta = game:GetService("UserInputService"):GetMouseDelta()
--if aiming then mouseDelta *= 0.1 end
springs_sway:shove(Vector3.new(mouseDelta.X / 200, mouseDelta.Y / 200)
local speed = 1
-- modifier can be dependent on a value changed when you're aiming, or standing still, etc.
-- this makes the bobble do more. or something.
local modifier = 0.1
if aiming then modifier = 0.01 end
-- See? Bobbing! contruct a vector3 with getBobbing.
local movementSway = Vector3.new(getBobbing(10, speed, modifier), getBobbing(5, speed, modifier),getBobbing(5, speed, modifier))
-- if velocity is 0, then so will the walk cycle
springs_walkCycle:shove((movementSway / 25) * deltaTime * 60 * velocity.Magnitude)
-- Sway! Yay!
local sway = springs_sway:update(deltaTime)
local walkCycle = springs_walkCycle:update(deltaTime)
rootPart.CFrame = camera.CFrame:ToWorldSpace(finalOffset)
rootPart.CFrame = rootPart.CFrame:ToWorldSpace(CFrame.new(walkCycle.x / 4, walkCycle.y / 2, 0))
-- Rotate our rootpart based on sway
rootPart.CFrame = rootPart.CFrame * CFrame.Angles(0, -sway.x, sway.y)
rootPart.CFrame = rootPart.CFrame * CFrame.Angles(0, walkCycle.y / 2, walkCycle.x / 5)
end
game:GetService("RunService").RenderStepped:Connect(update(dt))