viewmodels need springs or something idk saw it somewhere
tried adding springs to my viewmodel script and failed horribly
code
Viewmodel movement
local VmSpring = Spring.newSpring()
RunService:BindToRenderStep("ViewmodelMovement", Enum.RenderPriority.Camera.Value + 1, function(dt)
VmSpring:Update(dt)
local CF = workspace.CurrentCamera.CFrame * OffsetCFrame
VmSpring.Target = CF.Position
Viewmodel:PivotTo(CFrame.new(VmSpring.Position.X, VmSpring.Position.Y, CF.Z))
end)
Spring module im using
local Iterations = 8
function Spring.newSpring(Mass, Force, Damp, Speed)
local Self = setmetatable({}, Spring)
Self.Target = Vector3.new()
Self.Position = Vector3.new()
Self.Velocity = Vector3.new()
Self.Mass = Mass or 5
Self.Force = Force or 50
Self.Damp = Damp or 4
Self.Speed = Speed or 4
return Self
end
function Spring:Impulse(ImpulseVector : Vector3)
local X, Y, Z = ImpulseVector.X, ImpulseVector.Y, ImpulseVector.Z
if not X or X==math.huge or X == -math.huge then X=0 end
if not Y or Y==math.huge or Y == -math.huge then Y=0 end
if not Z or Z==math.huge or Z == -math.huge then Z=0 end
self.Velocity += Vector3.new(X, Y, Z)
end
function Spring:Update(DeltaTime : number)
local ScaledDeltaTime = (DeltaTime * self.Speed)/Iterations
for i = 1, Iterations do
local IterationForce = self.Target - self.Position
local Acceleration = (IterationForce * self.Force) / self.Mass
Acceleration -= self.Velocity * self.Damp
self.Velocity += Acceleration * ScaledDeltaTime
self.Position += self.Velocity * ScaledDeltaTime
end
end
Spring.__index = Spring
return Spring