Forum rules - please read before posting.

How to let the character keep the facing direction when moving up or down?

I use WASD to control movements. I set 2 facing directions and 4 movement orientations, and the frame flipping setting was "right mirrors left". When l press W or S to move up or down, my character always plays the walking-left animation, which is not what l want. I would like my character to play walking-right animation when moving up or down if he was already facing to the right, vice versa. How to achieve this?

Comments

  • It's tricky. I'll need to give it some thought - but I will update this shortly when I have something.

  • Thank you!

  • It should be possible with the aid of this custom script, attached to the character:

    using UnityEngine;
    using AC;
    
    public class ForceLeftRight : MonoBehaviour
    {
    
        bool isLeft;
    
        void Update()
        {
            AC.Char character = GetComponent<AC.Char> ();
            float angle = character.GetSpriteAngle ();
            if (angle > 1f && angle < 179f)
            {
                isLeft = true;
            }
            else if (angle > 181f && angle < 359f)
            {
                isLeft = false;
            }
            character.SetSpriteDirection (isLeft ? CharDirection.Left : CharDirection.Right);
        }
    
    }
    
  • It should be possible with the aid of this custom script, attached to the character:

    It works fine. Thank you sooooo much, Chris!

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.