public static float doFrictionX(float xv, float yv, float FRICTION) {
        float angle = (float) Math.atan(yv / xv);
        if (xv == 0) {
            if (yv == 0) {
                angle = 0;
            }
            angle = (float) Math.PI / 2;
        }

        // apply friction
        float fx = Math.abs(FRICTION * (float) Math.cos(angle));
        if (xv > 0) {
            xv -= fx;
            if (xv < 0) {
                xv = 0;
            }
        } else if (xv < 0) {
            xv += fx;
            if (xv > 0) {
                xv = 0;
            }
        } else {
            xv = 0;
        }

        return xv;
    }