Limiting current without generating (MUCH) heat (efficient)
What you (probably) want is a switching DC/DC converter with a current limit. You want it primarily for the current limiting. What it will do is lower its output voltage to the voltage level where the connected device consumes the current you have set as limit. This will be less than 5V (because at 5V your device consumes 2A), but still high enough that your device consumes (from your example) 0.5A.

Don't try to built this yourself, google or search the websites of the usuall suspects (for instance mouser or digikey for quality, aliexpress for low-budget).