This happens because negative events compel your attention with more insistence than positive events, so as you move toward your goal and problems arise, you will tend to fixate on what is in your way and forget to imagine how you want things to go.
If you have made this mistake, you know what to do. Take some time and relax your body. Remember, you need to relax first because otherwise your imaginings can be tainted by anxiety. Then just have fun imagining how you would like things to turn out.
Imagine the long term, but also imagine how you would like specific events to turn out. Stop struggling and let your imagination do its magic. Read more about visualizing here.
Adam Khan is the author of Self-Help Stuff That Works and Cultivating Fire: How to Keep Your Motivation White Hot.