Tracking of moving target with flyTo and trackedEntity

Hello,

This is my use case:

  • The camera is at an arbitrary position and looks at an arbitrary direction (e.g. looking from space down to earth)
  • There is an aircraft entity flying at real time speed or at replay times of 120x real time
  • The user hits a button
  • The camera shall smoothly turn towards the aircraft, then get closer to the flying aircraft up to a. certain distance (e.g. 500 m) and then track it

I tried to implement this using:

  • flyTo and then use trackedEntity: It seems that flyTo is not made to be used with fast moving targets. Once the camera was within the desired distance, I switched to tracked entity. However, this only worked for slowly moving targets
  • camera.move: I created my own tracking over each frame by calculating the vectors between camera and the moving target and advancing along the direction vector a certain distance for each frame. This was not optimal either and resulted in jerky camera. I then tried to detect if the camera was within the desired distance and set the trackedEntity. Due to sampling issues of the distance advancement at each step, the move was not stopped…
  • trackedEntity from the beginning on together with camera.lookAtTransform at the moving target: I calculated the distance increment per frame on my own, but then again resulted in not detecting if the camera was within desired distance and overshooting

What is the recommended way of tracking a moving target? Shall I use a simple PID controller?

Ultimately I want to use flyTo, because it has a nice transition in the beginning and does not move through earth, which other methods did.

Any help much appreciated.

Thanks!

I think a custom camera controller id likely best for this case. I would typically suggest something like your second implementation bullet. Can you explain more about the jerky camera? It might be possible to interpolate the position to be a bit smoother.

Taking a step back, we have received many requests for an easier and more robust camera API. I think this is a great representative use case and I am adding it to our notes.

Thanks!