Have you ever had the experience where you wake up in the middle of the night and imagine hearing or seeing something that turns out not to be there? Have you ever felt that you couldn't move when you woke up.
The state of transition between sleeping and wakefullness is know as the hypnopompic state. When you're asleep, your brain turns off your muscles, so that you (or at least, most people) don't actually move around even if they dream that they're moving around. When you transition back to being awake, sometimes your dream is still running.
There's also the Hypnogogic state, when you're falling asleep.
Here's an interesting article on this: