garrot

  • 11 يناير 2020
  • انضمّ(ت) 11 يوليو 2016

    thank you so much

    Is this thread still alive? I want to use playmaker with Spine, but I don't know if many years later this actions works nowadays.

    Hi everyone,
    We tried to achieve this smooth effect in the game by moving the mouse around the character:

    To do that, we spawn hierarchy on Unity and make a script (based on the law of sines) that allows the character's bones to follow the mouse here is the script:

    public class BoneAim
    {
        [SerializeField]
        public string boneName;
        [SerializeField]
        public float min;
        [SerializeField]
        public float max;
    }
    
    
    private float boneRotation( BoneAim boneAim, Spine.Bone topBone)
        {
            /****************************************************************************
             * A: Wrist     * 
             * B: Head      * DistB = DirAC.magnitude (distance between wrist and target)
             * C: Target    * DistC = DirAB.magnitude (distance between bones)
             ****************************************************************************/
            //Bone
            Spine.Bone bone = skeleton.FindBone(boneAim.boneName);
            string name = boneAim.boneName;
            //bone.UpdateWorldTransform();
            
    //World Positions: //wrist Vector3 A = bone.GetWorldPosition(this.transform); //Head Vector3 B = topBone.GetWorldPosition(this.transform); //target Vector3 C = GameManager.instance.getCursor().cursorPosition(); //Directions Vector3 dirAB = B - A; Vector3 dirAC = C - A; Vector3 dirBA = A - B; Vector3 dirBC = C - B; Vector3 dirCA = A - C; Vector3 dirCB = B - C; //Angles (original, debug only, we will change values after recalculate) float angleA = Vector2.Angle(dirAB, dirAC); float angleB = Vector2.Angle(dirBC, dirBA); float angleC = Vector2.Angle(dirCA, dirCB); /************* * RECALCULATING * *************/ //To calculate AngleC we need to knoe distB, distC and anlgeB //disB / sinB = distC / sinC // //sinC = disC * sinB / distB //after that-> anlgeA = 180 - angleB - angleC //Rot topBone (correct) angleB = getBoneWorldRotation(topBone); Vector2 dirB = angleToVector2(angleB); dirB.Normalize(); //Origanl head angle (angleB) that's the only angle we know angleB = Vector2.Angle(dirB, dirBA.normalized); float distB = dirAC.magnitude; float distC = dirAB.magnitude; float sinB = Mathf.Sin(angleB * Mathf.Deg2Rad); float sinC = distC * sinB / distB; //AngleC angleC = Mathf.Asin(sinC) * Mathf.Rad2Deg; //AngleA (world space) angleA = 180 - angleC - angleB; Debuggin.add(name, "angleA:" + angleA); //Exist the angle if (!float.IsNaN(angleA)) { float angleAOriginal = Vector3.Angle(dirAB, dirAC); //rotation += world andle - originalWorldAngle float angleRot = angleA - angleAOriginal; if (angleRot < boneAim.min) angleRot = boneAim.min; else if (angleRot > boneAim.max) angleRot = boneAim.max; bone.rotation += angleRot; } bone.UpdateWorldTransform(); return angleA; } private float getBoneWorldRotation(Spine.Bone bone) { float _rot = bone.WorldRotationX - 90; if (_rot < -180) _rot += 360; return _rot; } public static Vector2 angleToVector2(float degrees) { float rad = degrees * Mathf.Deg2Rad; return new Vector2(Mathf.Cos(rad), Mathf.Sin(rad)); }

    But we don't know why, in the game seems like the character has some problem with the angles:

    We want to rotate bones in a smooth way, here is our schedule:

    Do you have any idea of what could have hapened?

    Thanks


    skeletonAnim.UpdateLocal += skeletonAnimation_UpdateWorld;

    boneRotation is being called in "skeletonAnimation_UpdateWorld", that we added to UpdateLocal from skeletonAnimation.

    • تم التحرير

    hello akshaysule,

    did you try the solution above?, it works for me.

    Hello guys,

    Xelnath wrote

    Do you have multiple tracks running or just one?

    Nope, i just have one

    Thank you Pharan, this extra lines works and fix the problem. I don't have extra sprites any more.

    One more question, i have two characters in the final game (the images up here belongs to test project). I have one character with SkeletonAnimation and another with Mecanim. I have this issue in Mecanim too.
    Do you know if there any way to fix this issue in Mecanim too?

    Thanks.

    For this I use SkeletonAnimation, what is SkeletonGraphic?

    I tried a lot of things, and nothing changes, for example I put this after every animation:

    skeletonAnimation.skeleton.SetToSetupPose(); 

    and got same results, sprites still inherit properties.

    What can i do?

    Hi,

    When i export animations into Unity and play it, some sprites do weird things.
    It seems sprites inherit some properties when animation ends.

    For example, i have this three animations in Spine:
    -walk
    -crawling
    -grab an object

     Loading Image

    While in Spine looks good, in Unity the animation's sprites are completely mess:

     Loading Image

    How i fix that?

    I use Spine 3.3.07 and runtime release yesterday (Jul-11).

    • تم التحرير