That's an unnerving experience. It has happened to me - I've also experienced a VERY loud noise in that half-awake state. (The noise wasn't 'real'.) Are you familiar with this (ignore the horrid name, it's a very real and upsetting syndrome):
https://en.wikipedia.org/wiki/Exploding_head_syndrome