- 編集済み
Path Constraint Jumping
I'm having an issue with a looping path constraint. It's a closed path, so the first keyframe is at 0 and the last is at 100. When we bring this into Unity, the bone moving along the path moves around the loop and then when it gets to the end, it quickly goes around in the opposite direction before starting over. Here's a video: https://www.dropbox.com/s/bdwfs44z2dc5qic/path-constraint.mp4?dl=0
Please let me know if you have any ideas! Thanks in advance!
Is this a looping animation?
Can you describe how you are playing the animation?
Yes, this is a looping animation that happens over 120 frames. It's a closed circular path, so we just want the animation to loop around the full circle continuously. I'll attach screenshots of both the start & end frames in Spine.
Here's how we're playing it in Unity:
- It’s using a vanilla SkeletonAnimation component (not SkeletonAnimator)
- In code, we’re using AddAnimation to enqueue the next idle, after a random delay
16 May 2017, 09:50
Start:
End:
Is the problem happening in Skeleton Viewer? This will help indicate if the bug is in path constraint or the C#port.
Skeleton Viewer
Hey Nate! Thanks for the tip. Skeleton Viewer looks like a useful tool. Just viewed it in there and I'm seeing the jump when I switch from one idle to the next: https://www.dropbox.com/s/dr219j2xfahqg80/skel-viewer.mp4?dl=0
There is always one idle running on the idle track, and it’s always playing in a loop. The code we use to change the current idle is Spine’s built-in AddAnimation function, which is designed to queue the animation and not change until the current one is finished.
Any ideas after seeing this?
What exactly do you think is the wrong behavior in the video?
The backward movement is the wrong behavior. We aren't interrupting any idles in our project - we're just playing one right after another. For some reason, it's looping backwards (like it does in Skeleton Viewer) instead of starting our new idle from where the old idle ends (at our 0/starting point).
A few more notes:
- It seems like when you interrupt an animation (which in theory, we don’t DO, in Unity) Spine rewinds to the beginning of the first one, and then starts the new one
- if you DON’T interrupt an anim, but just let it finish… it seems to still rewind all the way back to the start again
18 May 2017, 15:45
I think we solved it! Looks like the mix duration was causing the issue.
If your animation keys position from 0, then when you start playing that animation, it starts at 0. If you are using a mix duration, for a mix a -> b
it will transition from the position of a
to the position of b
. This transition is linear, so it will look like the bones move backward along the path. If you don't use a mix duration, a
is discarded and b
is played right away, with no mixing (crossfading) between them.
For a closed path, we could be smarter and choose either forward or backward, whichever is the shortest path. This has some complexities though, because the shortest path between a
and b
can change over time, since both animations are still being applied. This is the same problem with mixing rotations and the solution is quite tricky (see AnimationState applyRotateTimeline!). We might be able to reuse the same logic, but it would make that tricky code even trickier since paths are percentages, not angles.