Why don’t you just animate the character moving back to its original position? You could simply animate the torso so it doesn’t interfere with other animations.
You could also use AnimationTrack:Stop(fadeOutTime) right before the animation ends to reduce the speed at which the character returns to the original position.
Code
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local anim = script.Animation
local track: AnimationTrack = animator:LoadAnimation(anim)
track.Priority = Enum.AnimationPriority.Action4
task.spawn(function()
while task.wait() do
local t = track.TimePosition
local duration = track.Length
print(duration - t)
if duration - t <= 0.05 then
track:Stop(5)
end
end
end)
while task.wait(10) do
track:Play()
end
Note: AnimationTracked:GetPropertyChangedSignal("TimePosition") does not work for whatever reason, so you will have to check it using a loop like I did.
Using a loop to check TimePosition is pretty inefficient. You can just use the track.Stopped:Connect() or GetMarkerReachedSignal if you want to trigger something at a specific time. The fadeOutTime in Stop() works, but it’s not a real fix for the movement if the animation is fundamentally broken or if you’re relying on on the loop’s timing to catch the end of the track. If you’van’t tried checking for ans marker, use that instead of a loop.
If you actually tried this before posting, you would realize it does not work because that is when the animation has already began to “fade out”.
This works, but you can’t simply create a marker on the last keyframe. You would need to duplicate the last keyframe, add the animation event on that, save the animation, and update the animation object(s). All of this is quite a bit of work - especially if you need to do this for multiple animations. The loop isn’t even that inefficient - it’s running performing extremely basic tasks. It has minimal impact on performance unless you’re playing on a literal potato.
The loop is fine for a single track, but it’s still a messy way to handle it. If you’re already manually managing the fade out with Stop(5), then using a marker is just more overhead you don’t want. Just use the fade out parameter and be done with it.
Ok I found out that, for some reason, the animation doesn’t actually change the Torso’s pos at all. Which is why the rig tries to run back to the Torso’s real pre-anim pos as fast as possible before the anim ends, and obviously when the rig dies the anim ends with it. I have some ideas what to do about that. Maybe something to do with worldroot, because it seems like worldroot methods use parts’ actual positions and not the numbers they say they are. Then i can actually set the torso pos to where the torso is supposed to be in the real world.
If the animation isn’t actually moving the Torso in the engine, then you’re just fighting a visual illusion. Check if you have any other constraints or scripts overriding the CFrame during playback. If the part’s actual position isn’t changing, no amount of WorldRoot manipulation is going to fix the underlying animation mismatch.
So first you need this for root motion on NPCs, then slow the animation down to 0 right before the animation ends. Then somehow it works. This engine sucks.