• Runtimes
  • How to convert smooth animation to unity

Related Discussions
...

I'm trying to solve this problem 2d day and can't find solution. I've already asked at answers.unity3d.com but want to ask it here as well.

I need to transfer animation from spine to unity. Here is how it looks in spine

Image removed due to the lack of support for HTTPS. | Show Anyway


according to JSON Export Format

JSON Export Format wrote

The Bézier curve array has 4 elements which define the control points: cx1, cy1, cx2, cy2. The X axis is from 0 to 1 and represents the percent of time between the two keyframes. The Y axis is from 0 to 1 and represents the percent of the difference between the keyframe’s values.

here is what I see in input data

    [ 0.135, 0.74, 0.918, 0.17 ]

and this is coordinates for P1=(0.135, 0.74) and P2=(0.918, 0.17).
for all cases P0 = (0, 0), P3 = (1, 1)

At unity side, I need to provide outTangent for P0 and inTangent for P3 which is keyframe[0] and keframe[1] in case of curve has just 2 points.

here is my calculation (which doesn't show correct result):
i and nextI is a keyframe indexes of P0 and P3 in AnimationCurve,
tangentArray is json array contains data specified above [cx1,cy1,cx2,cy2]
parseFloat custom method, i can't use default (float)cx1 or float.parse(cx1)

    public static void setCustomTangents(AnimationCurve curve, int i, int nextI, JsonData tangentArray){
    float cx1 = parseFloat(tangentArray[0]);
    float cy1 = parseFloat(tangentArray[1]);
    float cx2 = parseFloat(tangentArray[2]);
    float cy2 = parseFloat(tangentArray[3]);
    float time = (float)(curve.keys[nextI].time - curve.keys[i].time);
    float value = (float)(curve.keys[nextI].value - curve.keys[i].value);
     
Keyframe thisKeyframe = curve[i]; Keyframe nextKeyframe = curve[nextI]; float outTangent = (cy1 * value)/ (cx1 * time); float inTangent = ((1 - cy2) * value)/ ((1 - cx2) * time); thisKeyframe.outTangent = outTangent; nextKeyframe.inTangent = inTangent; curve.MoveKey(i, thisKeyframe); curve.MoveKey(nextI, nextKeyframe); }

This is result in unity

Image removed due to the lack of support for HTTPS. | Show Anyway

It's very different, so I'll happy if someone will help me with it.