Hi, I want to lerp my viewmodel when a player is walking, so I do that by making a variable that detects if the player is walking and put it in a update function. Last step is to lerp it, but that’s the problem. I don’t know how to lerp the hands instead of instantly showing when they walk
Here’s how it looks like:
local Viewmodel = {}
Viewmodel.__index = Viewmodel
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
function Lerp(a, b, c)
return a + (b - a) * c
end
function Viewmodel.new()
local self = setmetatable({},Viewmodel)
self.LoadingAnimations = {}
self.LerpingValues = {}
self.LerpingValues.Equip = Instance.new("NumberValue")
self.LerpingValues.Equip.Value = 1
self.SwayCFrame = CFrame.new()
self.SwayAmount = -0.4
self.LastCameraCFrame = CFrame.new()
return self
end
function Viewmodel:Equip()
self.Camera = workspace.CurrentCamera
if workspace.Camera:FindFirstChild("Viewmodel") then
workspace.Camera.Viewmodel:Destroy()
end
self.Viewmodel = script.Viewmodel:Clone()
self.Character = Players.LocalPlayer.Character
self.Viewmodel["Left Arm"].Color = self.Character.Head.Color -- change left arm color
self.Viewmodel["Right Arm"].Color = self.Character.Head.Color -- change right arm color
self.Viewmodel.Parent = workspace.Camera
self.Settings = require(self.Viewmodel.Settings) -- settings gathered
self.LoadingAnimations.Walk = self.Viewmodel.AnimationController:LoadAnimation(
self.Settings.Animations.Viewmodel.Walk
)
--local EquipTween = TweenInfo.new(0.5, Enum.EasingStyle.Quart, Enum.EasingDirection.Out) -- tween equip
--TweenService:Create(self.LerpValues.Equip, EquipTween, { Value = 0 }):Play()
end
function Viewmodel:Update(DeltaTime)
if self.Viewmodel then
local Rotation = self.Camera.CFrame:ToObjectSpace(self.LastCameraCFrame)
local X,Y = Rotation:ToOrientation()
self.SwayCFrame = self.SwayCFrame:Lerp(CFrame.Angles(math.sin(X) * self.SwayAmount, math.sin(Y) * self.SwayAmount,0),0.1)
self.LastCameraCFrame = self.Camera.CFrame
-- offsets
self.Idle = self.Viewmodel.Offsets.Idle.Value
self.Walk = self.Viewmodel.Offsets.Walk.Value
local Offset = self.viewm
local Character = Players.LocalPlayer.Character
local Humanoid = Character.Humanoid
local isWalking = if Humanoid.MoveDirection.Magnitude > 0 then true
else false
if not isWalking then
Offset = self.Idle
else
Offset = self.Walk
end
self.Viewmodel:SetPrimaryPartCFrame(self.Camera.CFrame * self.SwayCFrame * Offset)
else
warn("Viewmodel not found or character is dead.")
end
end
return Viewmodel