public void createTail()
    {
        if (!canCreateTail) return;
        
        double dir = getDirection();

        double tailx = (dir == Const.left) ? X() + getWidth() : oldX();
        double taily = (dir == Const.up) ? Y() + getHeight() : oldY();
//Each tail segment is ratspeed in length because it is created every timer tick.
//That way each gap that is created when rat moves is 'patched' by a tail segment.
//Tail thickness is either rat width or height.
        double tailwidth = (dir == Const.right || dir == Const.left) ?
                Const.ratspeed : Const.ratwidth;
        double tailheight = (dir == Const.up || dir == Const.down) ?
                Const.ratspeed : Const.ratheight;

        Tail newtail = new Tail(tailx, taily, tailwidth, tailheight, this);
        getEntities().addEntity(newtail);
        lastTail = newtail;
    }