示例#1
0
    EnumPlayerDirection GetPlayerDirection(Vector2 PlayerMovementVector)
    {
        if (Mathf.Abs(PlayerMovementVector.y) > Mathf.Abs(PlayerMovementVector.x))
        {
            if (PlayerMovementVector.y > 0)
            {
                PlayerDirection = EnumPlayerDirection.Up;
            }
            if (PlayerMovementVector.y < 0)
            {
                PlayerDirection = EnumPlayerDirection.Down;
            }
        }
        else
        {
            if (PlayerMovementVector.x > 0)
            {
                PlayerDirection = EnumPlayerDirection.Right;
            }
            if (PlayerMovementVector.x < 0)
            {
                PlayerDirection = EnumPlayerDirection.Left;
            }
        }

        return(PlayerDirection);
    }
示例#2
0
 public void Awake()
 {
     rigidbody2d       = GetComponent <Rigidbody2D>();
     skeletonAnimation = GetComponentInChildren <SkeletonAnimation>();
     animator          = GetComponentInChildren <Animator>();
     LastVelocity      = Vector2.zero;
     PlayerDirection   = EnumPlayerDirection.Right;
 }
示例#3
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (!GameRule.get.IsGameActive())
        {
            rigidbody2d.velocity = Vector3.zero;
            LastVelocity         = Vector3.zero;
            return;
        }

        Vector2 PlayerInput = GetPlayerInputVector();

        PlayerDirection      = GetPlayerDirection(PlayerInput);
        rigidbody2d.velocity = Vector3.zero;
        rigidbody2d.velocity = PlayerInput * PlayerMovementSpeed;
        LastVelocity         = rigidbody2d.velocity;
    }