How Would I Go About Moving The Character To The Last Place A Animation Ended

Im aware there are posts about this but it never answers the simple question they always include velocity

if i want to do a crazy animation and make the player end up across the map I guess how would I move the player to the last place in the animation

I tried moving the cframe of the hrp to the torso but it did nothing so im not really sure what i can do

2 Likes

Detect when the Animation Track has ended / stopped connect a function then get the Last Position of the HRP. Then position the player to that Last Position

I believe the code may look something like this

local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://<your_animation_id>" 

local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)

animationTrack.Stopped:Connect(function()
    local lastPosition= humanoidRootPart.Position

    -- Move the character to that position
    humanoidRootPart.CFrame = CFrame.new(lastPosition)
end)

animationTrack:Play()

If the animation is always the same, and it, let’s say, puts you 1,000 studs in one direction across the map, just teleport the player 1,000 studs in that direction. @McGamerNick’s reply is probably the solution, but incase not, even if teleporting in that direction isn’t a very dynamic and is pretty sloppy, always works.

yea its just its more what @McGamerNick said i havent tried it out yet but its just if i have a animation that makes me jump backwards in the air and land or something it would cframe me to where the animation landed, im aware for this example you could use velocity stuff instead of moving the torso but im just saying if i want to move the torso and the whole body to a diffrent place in the game with a animation i want to actually be there when the animation ends

im using this for a grab animation so my character alone will be slightly moved forward at the end of the animation since its got a tiny lunge

you shouldn’t use “hrp.CFrame = (cframe value)” because it’s not a viable way to teleport a player. instead, you should do something like this

char:PivotTo((cframe value))

where char is the parent of the HumanoidRootPart.
in your case, you would want to do something like this:

local plrCFrame = hrp.CFrame

char:PivotTo(hrp.CFrame)

however, there’s another problem where you play the animation in the server, which you shouldn’t do. you should almost always play player animations inside a LocalScript. if you want to teleport the player to the CFrame when the animation ended, you would need to attach a RemoteEvent. like this:

animTrack.Ended:Connect(function()
    remote:FireServer(hrp.CFrame)
end)

server:

remote.OnServerEvent:Connect(function(plr, originCFrame)
    plr.Character:PivotTo(originCFrame)
end)

I thought local scripts can use PivotTo? If they are able too you’re creating unnecessary network bandwidth.

1 Like

by the way, in your case here:

I don’t really think you should do this in the first place. you might want to make the animation have a walking animation itself, but not move within the animation. instead you could make the player automatically move itself through forces

1 Like

you can, but that’s basically just setting a part position to somewhere client-wise. this will make the changes not visible for the server and other clients. I am unsure if this is still the case for players, but I still wouldn’t recommend because some stuff might be de-synced in a way

may I ask why isnt it a viable way to teleport the player I genuinely dont know why I use it all the time like what downsides does it have

also whats the downsides of playing animations on the server does it increase packets or memory alot? I also do it alot and dont really know the downside I know it wasnt good but I dont know why its bad I would assume packets since I assume smooth moving part on server aka tween or lerp = high packets

Client’s can control their own player character… hence why they can set their own walkspeed, play their own animations e.t.c

1 Like

Basically using PivotTo() is more secure since its a model and it ensures everything in the model gets moved accordingly-- Versus using PrimaryPart.CFrame.

Aka Roblox Built In Functions over anything most of the time.

1 Like

again, playing on the server will have the server wait until it gets the message for the animation to be played. it wouldn’t be relative to the client which makes it a tiny bit delayed, which is a big no-no in this case.

for setting the hrp CFrame, it’s a more worse way to go about doing it because :PivotTo() will move every other part along with the PrimaryPart, while setting the position of the rootPart relies on welds.

1 Like

Im horrible with grab skills currently as I never do them and I see people make the animations and include all the moving of the torsos and the grabber and the grabbed player moving around inside the animation not staying on the same spot so i did it like that then just welded the 2 players humanoidrootparts and the animation did the rest

for example the animation the 2 players characters start the animation inside eachother and in the first keyframe i pose them and get them to have some distance and do the whole animation from there but at the end it would return all the characters parts to the rootpart

so they would just sort of tween back to their orignal position so i didnt want that to happen so thats why I wanted to teleport the characters to their end of animation positions that was my thought process since not alot of grab tutorials exist other then the bad ones

1 Like

I understand. well have you tried the other solutions? any luck with them?

I tried lots of diffrent ways to Cframe the rootpart at the end of the animation but not really anything else i will not being cframing the root part any longer now though I did see a plugin or module earlier for a constant moving rootpart wherever the torso goes in your animations but i think it wouldnt really be worth using but i guess ill try just use velocity

its just i hate messing with velocity it always goes wrong i either overshoot the distance or it makes me slide forward too much or its too slow or too fast

1 Like

I don’t see why you can’t set the character CFrame. matter of fact I did that in one of my games where I was unable to use forces. however if you want to go down this path and you are having trouble with forces, just create a new post about it

1 Like

Perhaps this might help you?

yea this is what I was talking about I may try it