The most simple solution. You could simply decide how many tiles the player can move before the camera movement is required. It doesn’t have to be close to the edge. When player cross the threshold just change the camera position (X,Z) to the same as player.
Alternatively, you could have an invisible transform (an “observer”) that looks at the player, placed as a child of the camera. As the transform keep tracking the player, it changes its direction. You may decide than an angle of +/-30 degrees along X and Z axis, the camera should move.
In this topic LookAt / Target property or function for camera or any TCastleTransform - #3 by michalis @michalis gives a simple example of a “Look At” behaviour implementation. Just attach the behavior to the observer transform.
It is performance friendly.
During the camera movement you need to pause the “Look At” behaviour.
As an option, you could auto-calculate the min/max angle based on:
- h = camera height,
- d = maximum distance, or Tiles * tile_size, before you consider camera movement
by using simple trigonometry. If I’m not mistaken it’ll be ArcTan(d/h).
To animate the camera movement, you can also use behaviors which is easy, or just brute-force based on Update function.