Beispiel #1
0
    private void MovePlayer()
    {
        targetVelocity = speed * input;

        if (Vector2.Dot(input, rb.GetDirection()) <= 0)
        {
            rb.SetDirection(new Vector2(input.x, input.y));

            //prevents diagonal directions
            if ((int)rb.GetDirection().x != rb.GetDirection().x)
            {
                rb.SetDirectionX(0);
                rb.SetDirectionY(Mathf.Sign(rb.GetDirection().y));
            }
        }
    }