Is there a way to have NPCs stay where they are when animations end?

I can’t use CFrame because that effect looks glitchy-the player moves back to the starting position, then the animation ends, and then they move to where they were when the animation ended. It just looks weird.
Is there any way that I can just have them not move back to their original position when they finish the animation?

1 Like

I’m pretty sure that there is no way to prevent the NPC from returning to its starting position because animations always return the subject back to its starting position.

If the animation is simple enough, you could recreate it by lerping the CFrame of NPC’s PrimaryPart.

For example, if you wanted to make the NPC leap forward you would figure out where the CFrame position where the NPC would land and do something like this:

local startingCFrame = NPC.PrimaryPart.CFrame -- Define the CFrame of the NPC's PrimaryPart
local endingCFrame = startingCFrame * (NPC.PrimaryPart.CFrame.lookVector * 10) -- Define the ending CFrame, in this case it's 10 studs in front of the startingCFrame

for i = 0, 1, .01 do
    NPC.PrimartPart.CFrame = startingCFrame:lerp(endingCFrame, i)
    wait()
end

To make it more visually appealing, you could also play an (in place) animation while this lerp is happening.

P.S. I don’t know too much about lerping, so I advise you look into it. I wrote this as a sort of guiding answer, not a final solution.

Hope that helps, somewhat.

A quick tip, lerp isn’t advised to use to animate parts due to the release of TweenService.

On topic, though, you can make the animation 0.1 second longer and set a keyframe 0.1 seconds before the end of the animation with the ending pose you want, as well as setting a name for the keyframe. Then, it’s a simple as checking keyframeReached and comparing the name, and setting animationTrack’s speed to 0.

3 Likes

I suggested lerp because it isn’t really straight forward to Tween a model.

I’m assuming that the OP wants the NPC to play the animation more than once. If another animation is played on the NPC, it will return the NPC back to its starting position before playing.

I don’t want it to play more than once. Simply an animation where they do a little dance and then glide back off stage with a custom walking animation.

Oh. Then in that case, Xiousa gave a good solution. You should mark it as such to prevent further replies to this topic.