This version still uses the static distance implementation for finding the dead zone region, which simply measures the distance from the center of the screen. With this implementation, the character begins pushing the screen too early when moving further into space. Conversely, the character risks falling off the screen when moving too close to it.
In this version, we will constantly update the bonds as the character moves closer and further away from the camera. Additionally we will add dead zone the y-axis.
Let's set up a few variables to simplify scene configuration.
BoundsXOffset - defines how many units from the screen edge the camera should begin moving.BoundsZOffset - defines how many units from the screen top the camera should begin moving.For example, if you set BoundsXOffset to 100, the camera will start moving when the character is 100 units from either the left or right edge.
BoundsYFar - defines the maximum distance the character can be from the camera before it moves.BoundsYNear - defines the minimum distance before the camera is pushed back.For the Y-axis, we need separate far and near bounds, unlike X and Z axes.
<aside> 📌
Note that you can also use separate variables for left and right edge bounds if needed.
</aside>
To dynamically update the bounds, we need to calculate the distance from the screen's center to its edge. This allows us to update BoundsX and BoundsY.
Since the center-to-edge distance varies with character position, we must calculate based on the character's current distance.

When XEdgeOffset and YEdgeOffset are both 0.5, the intersection occurs at the screen's center.