Foresight

The forebrain determines what to do. The cerebellum determines how (and when) to do it. The midbrain determines why things should be done in the first place.

To help us avoid pain our cerebellum is constantly running simulations to see what is about to happen and to see what effect various actions we could take would have. It also sets off alarms to tell us when we should take immediate action.

So we are attracted toward pleasant things and repelled from unpleasant things. If our brains functioned the way that they should then we would only experience pain or pleasure when the path forward was clear. But we experience pain even when there is nothing we can do about it.