Fillet knife people are right. All others are wrong. I mean, sure the heat cutters work, but they also give a heat-cut edge so it's less gentle foam, usually. Also takes some time to figure out the right temp for each foam.
Also, avoid trying to cut 90° corners and NEVER cut blind holes. Build the stuff up from bits, and glue it together. This is how factories make foam liners, so follow their lead. Most contact cements and on Camie spray glue (I forget which number) will work on foam without melting it.
I have had a couple sensitive item cases destroyed by stupid people so had to reproduce complex shapes, got used to it so keep scrap foam and make little foam liners /constantly/ now. Just in the last two weeks added some foam to an ANVIS case to make a thermal fit better, and seized a Pelican case the wife wasn't using, made a better suppressor case for myself. Cutting and glueing to get the shapes I need, takes minutes.
Although cutting to the exact profile of your gun is pretty, it is harder to get right and not necessary for protection. You can cut straight pieces that the rifle bumps into, fits neatly inside, and still doesn't move at all then. Keep in mind, so even if you want to do contour cutting, if some part is going to be hard or is giving you fits (like contouring around the bottom of the stock or pistol grip) give up and leave a squared-off gap there and it will work fine, and look like it's on purpose.
Do also remember to leave some room to pick it up and insert it. If too tight it will pucker oddly, and you will have no place to grab the thing so will have your your dirty fingers shoving into the foam, cause it to deform, show the dirt eventually. Remember to leave a little (or big) cutout where you would grab it normally.