Ejemplo n.º 1
0
    //point the beaver in the same direction as it is moving
    void RotateBeaver(float x, float y)
    {
        // cancel all input below the threshold
        if (Mathf.Abs(x) < leftAnalogThresh)
        {
            x = 0.0f;
        }
        if (Mathf.Abs(y) < leftAnalogThresh)
        {
            y = 0.0f;
        }


        // CALCULATE ANGLE AND ROTATE
        if (x != 0.0f || y != 0.0f)
        {
            if (facingRight)
            {
                facingAngle = (Mathf.Atan2(y, x) * Mathf.Rad2Deg);
            }
            else
            {
                facingAngle = (Mathf.Atan2(y, x) * Mathf.Rad2Deg) + 180;
            }

            playerStateScript.SetFacingAngle(facingAngle);

            //beaver_sprite.transform.rotation = Quaternion.AngleAxis(facing_angle, Vector3.forward);
            transform.rotation = Quaternion.AngleAxis(facingAngle, Vector3.forward);
        }
    }