Beispiel #1
0
    private float Direction()
    {
        Vector2 ThorFacingDirection = ThorScript.GetFacingDirection();

        float angle = -90;                                                       // Default is Down because that's the direction the player is facing when the game starts

        if (Mathf.Abs(ThorFacingDirection.x) > Mathf.Abs(ThorFacingDirection.y)) // If player last movement was horizontally
        {
            if (ThorFacingDirection.x > 0)
            {
                angle = 0; // Right
            }
            else
            {
                angle = 180; // Left
            }
        }
        else // If player last movement was vertically
        {
            if (ThorFacingDirection.y > 0)
            {
                angle = 90; // Up
            }
        }

        return(angle);
    }