I have a heater/AC UNIT installed in my attic and in winter the heat from the unit melts the snow turning into ice and creates a nitemareso I want to put insulation in the rafter to insulate the roof from the heater. Will this work? Any tips on how far down to go? Is it ok for rafter insulation to be right down to ceiling insulation or should I leave a gap?
What you are basically considering - converting a vented attic to conditioned space - is generally a good idea for energy efficiency and preventing ice dams when you have ductwork or HVAC equipment in an attic. However, it is not a trivial task, and done incorrectly, can rot your roof sheathing.
Insulating between the rafters is the riskiest approach - it will significantly hinder the drying of any moisture that reaches the sheathing, allowing it to rot.
A better approach is to attach rigid insulation to the underside of the rafters, leaving the space between the rafters as vented channels. 2" of rigid foam, with the seams taped, can make an effective "hut" inside your current attic space to keep the warmth from your home and your furnace from reaching the roof, preventing ice dams, and improving the efficiency of your HVAC equipment in winter and summer.
x2 on rigid insulation on the bottom of the rafters and insulating the ductwork. I would also assess your overall attic venting - maybe adding a vent near the equipment.