Smoothing animations with weight

Hello! I’m trying to make walking, idle, and sprint animations blend into each other but just can’t get it right for the life of me.

Either no animations play when I move, they bug out and overlap, or just don’t fade. If anyone has any techniques or a way to fix my function, please let me know.

local function PlayAnimation(anim)
	
	for i, animation in pairs({IdleAnim,WalkAnim,SprintAnim}) do
			if animation.IsPlaying then
				local TargetWeight = Instance.new("NumberValue")
				TargetWeight.Value = 1
				local Tween = game:GetService("TweenService"):Create(TargetWeight, TweenInfo.new(0.25, Enum.EasingStyle.Exponential), {Value = 0}):Play()
				
						TargetWeight:GetPropertyChangedSignal("Value"):Connect(function()
							animation:AdjustWeight(TargetWeight.Value)
							if TargetWeight.Value <= 0.05 then
								animation:Stop()
							end	
						end)
			else
				anim:Play(0 ,0)
				
			local TargetWeight = Instance.new("NumberValue")
			TargetWeight.Value = 1
			local Tween = game:GetService("TweenService"):Create(TargetWeight, TweenInfo.new(0.25, Enum.EasingStyle.Exponential), {Value = 1}):Play()

			TargetWeight:GetPropertyChangedSignal("Value"):Connect(function()
				animation:AdjustWeight(TargetWeight.Value)
				
			end)
			end
		end
	
	
end
2 Likes

U can just set animation weight when u’re uploading it. Works fine for me, never changing it by the script before. For example there is my code, each animation is just Movement weight

if speed > 0.5 then
		if self.IsCrouching then
			self:PlayTrack("CROUNCH", ANIM_CONFIG.SPEEDS.CROUNCH)
		elseif self.IsRunning then
			self:PlayTrack("RUN", ANIM_CONFIG.SPEEDS.RUN)
		elseif self.IsShiftLock then
			if self.IsSlow then
				local camCF = self.Camera.CFrame
				local rel = camCF:VectorToObjectSpace(moveDir)
				if math.abs(rel.X) > 0.5 and math.abs(rel.X) > math.abs(rel.Z) then
					self:PlayTrack(rel.X > 0 and "WALK_RIGHT" or "WALK_LEFT")
				else
					self:PlayTrack("WALK", ANIM_CONFIG.SPEEDS.WALK_SLOW)
				end
			else
				self:PlayTrack("WALK", ANIM_CONFIG.SPEEDS.WALK)
			end
		else
			self:PlayTrack("WALK", self.IsSlow and ANIM_CONFIG.SPEEDS.WALK_SLOW or ANIM_CONFIG.SPEEDS.WALK)
		end
	else
		if self.IsCrouching then
			self:PlayTrack("CROUNCH", 0)
		else
			self:PlayTrack("IDLE")
		end
	end
1 Like

Sorry for any confusion, I don’t mean animation priority. the sprint and walk are both Movement while the Idle is idle. However, I want the transitions between the animations to be smooth and that’s what I am trying to achieve with the animation weights

1 Like

Can u record a video or give a full script so i can test it by myself? Transition from idle to walk and walk to run is smooth enough by default for me.

1 Like

When switching between states, the animations are smoother

and sorry my animations suck lol

Hello, I believe this can be done with the FadeTime parameter of the AnimationTrack:Play(FadeTime: number) and AnimationTrack:Stop(FadeTime: number). This will increase and or reduce the transition time between animations, since the default roblox value of 0.1 is relatively low.