This is a common type of hypnagogic hallucination, a hallucination that you have as you are falling asleep, halfway between being asleep and being awake. (A hypnompic hallucination is a situation that you have when you are waking up.)
It's common to hallucinate a scary figure during a hypnopompic hallucination, and to have a feeling of intense fear.
People experience similar hallucinations during
sleep paralysis.