I’m trying to change the default R15 animations dynamically - sometimes a character is crouched and the walk/run animation will need to change. I’ve looked into this pretty extensively, and per the documentation it should be as simple as:
> Documentation
Changing any of the AnimationId’s under the Animate script doesn’t seem to do anything and most of the related forum posts also reference this logic, which apparently is no longer applicable.
Is there any (simple) way to change default animations at runtime?
You don’t have to, all you have to do is listen to player.Running and check for the speed, if its slow then just make localplayer play crouched running animation instead
I’ve been able to get this to work to change out the whole set of animations.
The thing that tripped me up was I had to stop all the current animations or I’d get kind of a weird blend of multiple animations. This code stops all the animations so your new one can play. Call this immediately after setting AnimationId.
-- Stop all animation tracks
for _, playingTrack in animator:GetPlayingAnimationTracks() do
playingTrack:Stop(0)
end
I think that this could help you. You basically need to make your crouching/running/walking animation have more importance than the default ones, so they will be played instead of the default ones.
It took a while to figure out what exactly this meant, but at the end of the day what worked was ignoring default animations altogether. Instead, check the state of the Humanoid, as well as the magnitude of the MoveDirection. If your player is crouched, do something like this to play the crouch walking animation and override the default animation:
if HumanoidState == Enum.HumanoidStateType.Running and Humanoid.MoveDirection.Magnitude ~= 0 and crouching == true then
crouchTrack:Stop()
crouchWalkTrack:Play()
elseif HumanoidState == Enum.HumanoidStateType.Running and Humanoid.MoveDirection.Magnitude == 0 and crouching == true then
crouchWalkTrack:Stop()
crouchTrack:Play()
else
crouchTrack:Stop()
crouchWalkTrack:Stop()
crouching = false
end