I’m trying to get the UI to follow a point in world space, but whenever the camera rotates, it lags behind. When it’s just the camera moving or the target moving, it tracks just fine, but during camera rotation it seems to lag behind. I am using Cinemachine for control of the camera, so I suspect that has something to do with my problem. I have tried putting my reposition-code in update, lateupdate, and fixedupdate functions to no avail, which is when I stumbled upon the CinemachineCore.CameraUpdateEvent, except that didn’t solve the lag problem with rotations. Any help would be appreciated.
This is the code I am using to position the UI
private void OnEnable()
{
CinemachineCore.CameraUpdatedEvent.AddListener(UpdatePosition);
}
private void UpdatePosition(CinemachineBrain _)
{
Vector3 screenPosition = m_Camera.WorldToScreenPoint(m_Target.position);
RectTransformUtility.ScreenPointToLocalPointInRectangle(m_Parent, screenPosition, m_Camera, out Vector2 localPos);
m_RectTransform.localPosition = localPos;
}