Mindrust

Hello,

I'm new to spine and I have an issue when I play an animation on a second track, the constraints/bones affected by that animation "freezes" when the animation ends.
I'm probably doing something wrong but I can't figure out what.
Here's an extract of my code controlling the animations:
public void PlayStart(){
skeletonAnimation.AnimationState.SetEmptyAnimations (0);
skeletonAnimation.AnimationState.SetAnimation (0, "Run", true);
}

public void PlayHit(){
skeletonAnimation.AnimationState.SetEmptyAnimation (0, 0);
skeletonAnimation.AnimationState.SetAnimation (0, "Hit", false);
skeletonAnimation.AnimationState.AddAnimation (0, "Run", true, 0);
}

public void PlayLaneChange(MoveDirection _direction){
if (_direction == MoveDirection.Up) {
skeletonAnimation.AnimationState.SetAnimation (1, "ChangeLaneUP", false);
} else {
skeletonAnimation.AnimationState.SetAnimation (1, "ChangeLaneDown", false);
}
}
when I start the game I call PlayStart, I have some other animations that I can call when the player gets hit or when he attacks and so on. This only modifies the track 0 and all seems to work fine. But as soon as I play an animation on track 1 so that I can blend the "ChangeLane" animation with the run animation, it breaks the constraints/bones that are modified by the "ChangeLane" animation and the animations from track 0 can't modify them until I do a SetEmptyAnimations().

I've tried to search for solutions online but I couldn't find anything, any idea what I can do to fix that?

Thanks!
Mindrust
  • Posts: 3

Harald

What do you mean by 'it breaks the constraints/bones that are modified by the "ChangeLane" animation and the animations from track 0 can't modify them'? Does it produce weird bone rotations?
User avatar
Harald

Harri
  • Posts: 445

Mindrust

I made a quick video to show what I mean: https://drive.google.com/open?id=1EK-Y1Rw_WcCyBh4r3QgN7GnYTGy-O6ug

the changelane animation plays at around 2 sec, and when it's done, the bones it affected freeze.
Mindrust
  • Posts: 3

Pharan

After the animation duration elapses for non-looping animations, the pose at the end of the animation will continue to be applied unless you tell AnimationState to remove it.
Here, this applies to SetAnimation(1, "ChangeLaneUP", false); So any bones that "ChangeLaneUp" keys will continue to be under its control until you stop its playback on track 1.

I think what you want for PlayLaneChange is something like this:
public void PlayLaneChange (MoveDirection _direction) {
const float MixDuration = 0.5f;
var state = skeletonAnimation.AnimationState;
if (_direction == MoveDirection.Up) {
state.SetAnimation(1, "ChangeLaneUP", false);
state.AddEmptyAnimation(0, MixDuration, 0f);
} else {
state.SetAnimation(1, "ChangeLaneDown", false);
state.AddEmptyAnimation(0, MixDuration, 0f);
}
}
User avatar
Pharan
  • Posts: 5366

Mindrust

Thank you very much! that worked great! :)
Mindrust
  • Posts: 3


Return to Unity