Enemy and Player being visible to camera

How would you implement a way where the enemy should be visible in the camera. I don’t know how to go about but I think there should be something of this sort when implementing, { float distance = Vector2.Distance(Enemy, player). }
The main objective is for the player to escape the enemy, so I do not want the enemy falling off behind and not being visible in the game camera while the player speeds off away.

I used cinemachine to allow 2d follow camera but whenever the player and enemy are visible in the camera, there is a conflict. The camera does not seem right since it’s not smooth. You, therefore, have to try to force the player away from the enemy from the camera then the camera goes back to being smooth.

you can check if Camera.WorldToViewportPoint(targetPosition).x is greater or less than 1. Any higher than 1 is off screen. Here is the api: Unity - Scripting API: Camera.WorldToViewportPoint. Or the easy way would be using OnBecomeInvisible() {} or OnBecomeVisible() {}

Thanks for the info. How about the camera conflict…