Unwanted teleporting when playing animation

Hello. As the title suggests whilst I play an animation (in this case a running animation) my character teleports precisely -340282346638528859811704183484516925440 studs in the Y axis, I’m not even exaggerating. But why?

There are no bugs at all in the code, all I’m doing is juggling between 3 animations using adjust weight, but only for the part there I adjust both the speed and weight of the running animation does my character teleport to a stupid range!

ForwardWalkAnimation:AdjustSpeed(ForwardAnimationWeight >= 0 and 1 or -1)
ForwardWalkAnimation:AdjustWeight(math.min(1, MovementVelocity.Magnitude/6) * math.abs(ForwardAnimationWeight), .1)
		
RightWalkAnimation:AdjustWeight(math.min(1, MovementVelocity.Magnitude/6) * RightAnimationWeight, .1)
		
LeftWalkAnimation:AdjustWeight(math.min(1, MovementVelocity.Magnitude/6) * LeftAnimationWeight, .1)

-- Beneath this line is the issue causing this weird glitch

RunAnimation:AdjustSpeed(MovementVelocity.Magnitude/5.5/1.99)
RunAnimation:AdjustWeight(math.max(0, (MovementVelocity.Magnitude/6 - 2)/2+.5),.1)

So is this the animation itself that’s causing it? I have no idea, so what do you think the problem is?

Try not to pass 0 or a negative weight value in :AdjustWeight and see if it goes away.

You can do something like math.clamp(weight, 0.01, 10) or by setting your math.max(0, …) to math.max(0.01, …).

1 Like

Sadly that didn’t fix it! But something about adjusting the weight is causing this issue :face_with_monocle:

Edit: I found that both the adjust weight and adjust speed correlate to this bug, not just adjust weight

After some more debugging I’ve found the issue looks to be the fact that Roblox has issues when playing multiple animations with different weights for each and every one of them.

Turns out that it was just that, a Roblox bug. In case anyone sees this I want to make one thing clear Optimise your code to edit no more than 4 animations at once nor play to many animations at once!!! Since Roblox hasn’t patched this yet I can only give that recommendation. Thank you @treebee63 for your tip and have a nice day :wink:

1 Like

I am skeptical of this because roblox got it working.

I recommend you take a look at roblox’s strafing system as the implementation. They implemented exactly what you are trying to do with your code.

  1. Create new place
  2. game.Player.UseStrafingAnimations = true
  3. game.StarterPlayer.LoadCharacterAppearance = false (strafing animation can work on your avatar as long as you’re using the default animations, otherwise it won’t work)
  4. Hit play and spawn your character
  5. Look in your character’s Animate

I’ve included the relevant chunk of code here:

	for n,v in pairs(locomotionMap) do
		-- if not loco
		if h[n] > 0.0 then
			if not v.track.IsPlaying then
				v.track:Play(runBlendtime)
				v.track.TimePosition = groupTimePosition
			end

			local weight = math.max(smallButNotZero, h[n] / sum2) -- non-zero weight
			v.track:AdjustWeight(weight, runBlendtime)
			v.track:AdjustSpeed(animSpeed)
		else
			v.track:Stop(runBlendtime)
		end
	end

You can see they used a non-zero weight here too and they’re managing over 20+ animations! Weight, FadeTime, Speed, it still works fine. I recommend you go back and compare your code to theirs, or just use their code.

1 Like

Ok, for now I found a crude fix to my issue but if I stumble upon this issue again I’ll use this to my advantage! Tanks again : )

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.