Search Unity

Question Sprite following mouse jumping around due to Cinemachine Virtual Cam

Discussion in 'Cinemachine' started by charles_xl, Jul 24, 2020.

  1. charles_xl

    charles_xl

    Joined:
    Oct 4, 2016
    Posts:
    87
    Hey there!

    I have a sprite following the mouse cursor by a simple screen to world position conversion. I have a virtual camera following my player, now when the camera is static and I move the cursor it works fine and updates properly. But the problem arises when the camera moves to follow the player, the cursor jumps around (almost like a ghost sprite). Any idea what's causing this or how to fix it? Do I need to lock the camera on the Z axis? Thanks in advance.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,719
    It most likely has to do with script execution order. Camera is moved in CinemachineBrain.LateUpdate. Make sure to position your cursor after that happens.

    You can do it by editing the script execution order and putting your cursor script after CinemachineBrain (use LateUpdate, not Update, to position the cursor). Alternatively, you can add a handler to CinemachineCore.CameraUpdatedEvent, and put your cursor placement code in that handler.

    See this thread: https://forum.unity.com/threads/too...-cinemachine-moves-video.679447/#post-4547422
     
    Delumine, ToastedBeans and charles_xl like this.
  3. charles_xl

    charles_xl

    Joined:
    Oct 4, 2016
    Posts:
    87
    That makes so much sense, appreciate the prompt reply and thank you!!