grankor

Resolved

I'm programming a game with a partner, he's using Spine to animate (cause I'm a terrible artist).

Anyways, we have a character that has multiple animations, left and right facing. (2D Platformer)

I can get the Right-facing animations to work until we swap left. Then NONE of the right animations show up in-game.
It'll switch between the left animations still,
and in unity the Skeleton Animation script will recognize the changes. They just aren't rendering.

Any ideas?

Code example:
using UnityEngine;
using System.Collections;

public class Anthony : MonoBehaviour {

public float speed;
public GameObject playerCamera;

[SpineAnimation]
public string idleRightAnimation;

[SpineAnimation]
public string idleLeftAnimation;

[SpineAnimation]
public string walkRightAnimation;

[SpineAnimation]
public string walkLeftAnimation;

[SpineAnimation]
public string hookRightAnimation;

[SpineAnimation]
public string hookLeftAnimation;

[SpineAnimation]
public string touchRightAnimation;

[SpineAnimation]
public string touchLeftAnimation;

public static bool action;

private SkeletonAnimation skeletonAnimation;
private string walking;
private GameObject actionObject;
private float actionDelayTime;

void Start () {
skeletonAnimation = GetComponent<SkeletonAnimation> ();
walking = "right";
action = false;
actionDelayTime = 0f;
}

void Update () {
if (actionDelayTime != 0) {
actionDelayTime--;
}


if (Input.GetKey (KeyCode.Space) && actionDelayTime <=0) {
actionDelayTime = 180;
if (walking == "right") {
skeletonAnimation.AnimationName = touchRightAnimation;

} else {
skeletonAnimation.AnimationName = touchLeftAnimation;
}
action = true;

} else {
action = false;
if (Input.GetKey (KeyCode.LeftArrow)) {
walking = "left";
transform.position += Vector3.left * speed * Time.deltaTime;
skeletonAnimation.AnimationName = walkLeftAnimation;
transform.eulerAngles = new Vector3(0, 0, 0);

}else if (Input.GetKey (KeyCode.RightArrow)) {
walking = "right";
transform.position += Vector3.right * speed * Time.deltaTime;
skeletonAnimation.AnimationName = walkRightAnimation;
transform.eulerAngles = new Vector3(0, 0, 0);

} else {
if (walking == "right"){
skeletonAnimation.AnimationName = idleRightAnimation;
} else {
skeletonAnimation.AnimationName = idleLeftAnimation;
}
}

if (Input.GetKey (KeyCode.UpArrow)) {
transform.position += Vector3.up * speed * Time.deltaTime;
}
if (Input.GetKey (KeyCode.DownArrow)) {
transform.position += Vector3.down * speed * Time.deltaTime;
}

float newY;
if (transform.position.y > 0) {
newY = Mathf.Clamp (transform.position.y, 4.3f, 6.78f);
} else {
newY = Mathf.Clamp (transform.position.y, -7.2f, -4.6f);
}
grankor
  • Сообщения: 3

Pharan

When you say "aren't rendering", do you mean the skeleton doesn't change its animation, or it disappears completely?
Аватара пользователя
Pharan
  • Сообщения: 5366

grankor

It's still appearing. It just continues the same animation.

However, this only happens when switching between certain animations, and with testing it only seems to happen when changing from left facing to right facing animations.

Going from walking to idle is no problem, but left walking > right walking doesn't work.
grankor
  • Сообщения: 3

Pharan

Try adding this line to your Start method:
skeletonAnimation.state.Start += delegate { skeletonAnimation.skeleton.SetToSetupPose(); };
And if that fixed it, is it possible that your left and right animations were completely identical except for the fact that one set was facing right and the other was facing left?
If that's the case, did you know you don't have to make one set of animations per left-right direction? You can use skeleton.flipX.

You can find more info here: https://github.com/pharan/spine-unity-docs/
:)
Аватара пользователя
Pharan
  • Сообщения: 5366

grankor

Pharan писал(а):When you say "aren't rendering", do you mean the skeleton doesn't change its animation, or it disappears completely?

Try adding this line to your Start method:
skeletonAnimation.state.Start += delegate { skeletonAnimation.skeleton.SetToSetupPose(); };
And if that fixed it, is it possible that your left and right animations were completely identical except for the fact that one set was facing right and the other was facing left?
If that's the case, did you know you don't have to make one set of animations per left-right direction? You can use skeleton.flipX.

You can find more info here: https://github.com/pharan/spine-unity-docs/
:)
To answer your second question, the character isn't asymmetrical, so we needed a right & left animation.

But!!!!
skeletonAnimation.state.Start += delegate { skeletonAnimation.skeleton.SetToSetupPose(); };
FIXED!
You're my favorite person today. :)
grankor
  • Сообщения: 3

Pharan

Definitely adding this to the docs.

-- 29 Feb 2016 8:50 pm --

The reason why it didn't work was because you were using a negative scale key on your animation to make your skeleton face left.
But there was no corresponding positive scale key on the animations to make the skeleton face right.

By default, SkeletonAnimation's AnimationState doesn't make certain too many assumptions so it doesn't apply animation keys that aren't there.
This is why we had to force it to reset with every new animation played using.
skeletonAnimation.state.Start += delegate { skeletonAnimation.skeleton.SetToSetupPose(); };
That was an event handler that called SetToSetupPose on the skeleton every time a new animation starts.

We don't recommend this way of flipping your skeletons because it's double the number of animations you actually need, which can add up if you have a lot of animations.
Instead, we recommend using skeleton.flipX.
Read more about it here (newly added): https://github.com/pharan/spine-unity-docs/blob/master/Animation.md#left-and-right-animations
Аватара пользователя
Pharan
  • Сообщения: 5366


Вернуться в Unity