I attempted to script weight blending for the first time and encountered an issue with the animations. (run/walk blending with weight)
For some reason, occasionally when my character stops running and my animations attempt to blend from one to another, the arms will “spasm” quickly before going into position again.
The blending works by decreasing the weight of the animation that is supposed to be stopped and increasing the weight of the animation that is supposed to be played. If the weight variable is lower or equal to 0.01, it’ll stop automatically and if it is higher it will play automatically.
code that handles the animation blending/weighting:
RunService.Heartbeat:Connect(function(Delta)
local standingSpeed = self.CurrentState == "Running" and 0 or 0.35
for AnimName, AnimInfo in pairs(self.Weights.Movement) do
if AnimInfo.Weight <= 0.01 then
if AnimInfo.Animation.IsPlaying then
AnimInfo.Animation:Stop()
AnimInfo.Weight = 0.01
end
else
if not AnimInfo.Animation.IsPlaying and AnimInfo.CanPlay then
AnimInfo.Animation:Play()
AnimInfo.Animation.TimePosition = AnimInfo.TimePosition
elseif AnimInfo.Animation.IsPlaying and not AnimInfo.CanPlay then
local interp = Lerp(AnimInfo.Weight, 0.01, TweenService:GetValue(elapsed(self, 1 - standingSpeed), Enum.EasingStyle.Quad, Enum.EasingDirection.In))
AnimInfo.Weight = interp
AnimInfo.Animation:AdjustWeight(AnimInfo.Weight)
continue
end
end
if AnimInfo.CanPlay then
local target = (self.CurrentState == "Running" and 1 or 0.01)
local interp = Lerp(AnimInfo.Weight, target, TweenService:GetValue(elapsed(self, 0.75 - standingSpeed), Enum.EasingStyle.Quad, Enum.EasingDirection.In))
if string.find(AnimName, "Walk") or string.find(AnimName, "Sprint") then
AnimInfo.Weight = interp
end
if AnimInfo.Animation.IsPlaying then
AnimInfo.Animation:AdjustWeight(AnimInfo.Weight)
end
end
end
end)
video of the issue:
you can also see the value of the animations weights on the bottom right of the screen