Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to force internal animation CFrame value of joints to reset properly?

Asked by 9 years ago

Background information: Animations do not directly modify the C0/C1 values of joints -- they affect a hidden, internal CFrame between the C0 and C1, and this is according to CodeWriter, so the information is credible. Since it's internal though, it can't be modified directly.

When you stop an animation, normally it tweens back to the starting position where the internal CFrame value is CFrame.new() -- no rotation nor offset. But I've run into a couple cases where it does not get reset properly.

In this sprinting animation, the arms start off flat, but after the sprinting animation they're tilted: https://gfycat.com/RapidPolishedAsianporcupine

I have one animation that functions as both an unequip animation and an equip animation -- the last and start frame are the same, and they're both in the off-screen finish position of the unequip animation. To play an unequip animation, I play this with a fadeTime of however long I want it to take to unequip the weapon, and when I want to play the equip animation, I instantly snap the arms to their off-screen, unequipped position with a fadeTime of 0 in Play() and stop the animation with a fadeTime of however long I want it to take to equip the weapon.

The unequip animation for assault rifles titles the gun slightly, and when it is done playing, it appears the internal CFrame value is still rotated because the gun is rolled a bit instead of flat: http://giant.gfycat.com/LikableWindyDwarfrabbit.gif

Each weapon uses its own equip/unequip animation -- in the above gif, starting with the rifle already equipped, the order is:

Unequip (Assault Rifle animation), Equip (Pistol animation), Unequip (Pistol animation), Equip (Assault Rifle animation), repeat from start

Animation-wise, the equip code is:

unequipAnimation:Play(0,1,1)--Instantly snap gun to off-screen with unequip animation since fadeTime is 0
unequipAnimation:Stop(0.24)--Tween gun back to default over 0.24 seconds with fadeTime of 0.24

The unequip code is:

unequipAnimation:Play(0.12,1,1)--Tween from default to off-screen over 0.12 seconds with fadeTime of 0.12
wait(.12)--Wait for animation to finish
unequipAnimation:Stop(0)--Instantly stops animation so equip animation for next weapon can take over

There is no delay from the end of the previous weapon's unequip and the new weapon's equip.

If I add this after the equip code (immediately after -- not delayed):

unequipAnimation:Play(0,1,1)
unequipAnimation:Stop(0)

The problem is reversed and the pistol is titled instead of the assault rifle: http://giant.gfycat.com/DizzyDefiantAmethystsunbird.gif

Someone suggested I play a blank animation to reset the internal CFrame value, but it did not work. I played an animation with all parts excluded with a fadeTime of 0 and the roll of the gun was still messed up -- it was not reset.

Has anyone experienced this problem before and knows a way to fix this?

Answer this question