So I’m working on a backpack system similar to the last of us and It works pretty well, however Im experiencing a minor issue with a small visual animation bug.
The way it works is that there is a open animation, and then when that is finished we switch to the idle animation and then when a button is released we play the close animation and close it.
The problem is occuring when we transfer from the open animation to the idle.
the idle will “hesitate” and the character will glitch back to its normal state before proceeding to play the idle.
it only happens when the backpack is opened for the first time,
which leads me to the conclusion that its an issue with preloading.
Here is a small portion of the backpack animation system (which is server sided)
local openTrack = Animator:LoadAnimation(openAnim)
local closeTrack = Animator:LoadAnimation(closeAnim)
local idleTrack = Animator:LoadAnimation(idleAnim)
idleTrack:Play()--====
idleTrack:Stop()-- i have tried this to get rid of the bug
local closeDuration = closeTrack.Length
local failSafeTime = closeDuration + 2 -- Add a buffer in case of slight delay
local function stopAllAnim()
for _, track in ipairs(Hum:GetPlayingAnimationTracks()) do
track:Stop()
end
end
--Backpack animaions
if toggleStatus == true then -- Opening Bag
backpackOpen = true
local sound = backpackOpenSound:Clone()
sound.Parent = character.PrimaryPart
stopAllAnim() -- Stop all other animations to prevent overlap
openTrack:Play()
openTrack.Stopped:Connect(function()
if backpackOpen then
if not idleTrack.IsPlaying then -- Ensure idleTrack doesn't replay unnecessarily
idleTrack:Play()
end
end
end)
and then here is the preloader for animations:
for index, animation in ipairs(animationAssets) do
loadingStatusText.Text = "Loading Animation: " .. animation.Name
ContentProvider:PreloadAsync({animation})
end
Debris:AddItem(animationsFolder, .1)