[RPG] Can you ready an action to attack a hidden creature before it attacks you

dnd-5ereadied-actionstealth

The hidden creature is in an adjacent room, he has cunning action, and is taking the hide action every turn after shooting his arrow. He's popping his head, taking the attack action, moving to total cover, and taking the hide action as a bonus action.

The combat has started a few rounds ago and the character that is trying to ready an action is at 1 hp.

Can I ready an an action to shoot an arrow at the hidden creature after he pops his head but before he makes his attack? Considering that he has succeeded on his stealth check?

Best Answer

When you try to hide, make a Dexterity (Stealth) check. Until you are discovered or you stop hiding, that check's total is contested by the Wisdom (Perception) check of any creature that actively searches for signs of your presence. (PHB 177)

So it depends on whether the creature comes out of hiding to attack.

1) If he can stay obscured while making the attack, the result of his stealth check and your opposing perception check stands and he can make his attack unseen. Also note that unless you take an action to try and discover his position, you are not allowed an active perception check, his stealth check is contested by your passive perception. However:

lf you are hidden-both unseen and unheard-when you make an attack, you give away your location when the attack hits or misses. (PHB 195)

So after the attack you would have a chance to attack him with a readied action. Your attack is still with disadvantage (as it is against an unseen target).

2) If he gives up hiding to attack, you automatically notice him and have a chance to use your reaction. He also has to repeat his stealth check if he wishes to hide again.