Camera like in Duke Nukem (platformer, not 3d shooter)

In original DOS Duke Nukem (platformer) and possibly Duke Nukem 2, camera obeys following rules for vertical scrolling:

[list=][]Scrolls to the player only when he’s on ground
]Scrolls to the player when he is about to leave the screen[/list]

While I know how to do 1 (I’ll use separate, invisible “Camera” object to center on instead of player), I don’t know how to detect if player is about to leave screen vertically. He’s still inside screen, but few pixels more and he’ll be off, so we need to scroll to him before that happens.

Can anyone help me on this? Basically I need to detect if player is about to leave screen space.

Maybe not practical but what I would try is to use an object as a sensor to check.
For example:

add an object to Duke to move with him, make it invisible the object and destroy object outside the screen. If object destroyed that means, Duke is about leave the screen, if object destroyed, after 1 sec or so, recreate object to get ready for next time if needed.


use an invisible border around the screen that moves with the camera and add an object to duke, check if object is colliding with the border, if yes that means Duke is about to leave.


place invisible objects in to the scene, if Duke is in collision with any invisible object, that means he is about to leave

I’ll probably use invisible border idea. Seems most easy to implement. Though I’d prefer solution where I wouldn’t need to use any non-essential objects at all.

Use the third solution but check collision with essential scene objects, design the scene to fit.