Work on something else - pick a small big to fix, an alignment issue - something small that won't take you more then 5-10 minutes to fix. Do a couple if you have to / have a back log.
Another that has worked for me - work on a different feature - step away from the problem you had to work on, and work on a different one. While you do that, your mind will be working on the original problem and it might be more clear when you come back to it.
As for the walking away / going for a walk or something - a long hot shower might help - I can't tell you how many times I came up with ideas just standing in the shower, listening to the water and not really thinking about anything. It's almost like meditation.