The Restrained Condition
The official game rules about player movement, grappling, incapacity, restraint, and engagement are very detailed. We greatly simplify movement by declaring, “If you can see something, you can engage it,” unless the text tells you otherwise. One of those exceptions is when an adventurer is Restrained.
A Restrained adventurer is unable to move. Being held in a tentacle and stuck in a web are common examples! The adventurer is able to attack normally with ranged attacks like spells or crossbows. But for hand-to-hand combat, like swords, axes, or touch spells, they can only attack something standing next to them. It’s safe to say that if a monster attacks a player with a hand-to-hand attack, the player can attack it. Otherwise, the player is stuck.
Usually, the player can remake their Saving Throw at the end of their turn to free themselves, but check the individual description.