Forum rules - please read before posting.

Trigger a Script When a Spine Character Changes Direction

Hi, I’m creating a 2D game using Spine animation, and I’m looking for some advice.

I want to trigger a script when my Player or NPC, made with Spine, changes their walking direction.
Specifically, I’d like to toggle certain character skins depending on the direction they’re facing. For additional context, my character only has a left-side animation, and I’m using "Right Mirror Left" to handle the right-side movement.

Any guidance on how to approach this, or which references I should use, would be greatly appreciated. Thank you so much.

Comments

  • You can use the character's GetSpriteDirectionInt function to work out which direction they're facing.

    Roughly speaking:

    int lastDirection = -1;
    void LateUpdate ()
    {
        int newDirection = GetComponent<AC.Char> ().GetSpriteDirectionInt () == 2;
        if (newDirection != lastDirection)
        {
            bool isFacingRight = (newDirection == 2);
            if (isFacingRight)
            {
                // Switched to the right
            }
            else
            {
                // Switched to the left
            }
    
            lastDirection = newDirection;
        }
    }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.