Search Unity

Question GetMouseButtonDown and Cinemachine

Discussion in 'Cinemachine' started by TenEightCME, Sep 6, 2022.

  1. TenEightCME

    TenEightCME

    Joined:
    Jun 5, 2016
    Posts:
    5
    I have quickly learned that I need to use FixedUpdate vs update when working with Cinemachine. I am running into a problem now where I want to use Input.GetMouseButtonDown within FixedUpdate. This function needs to be executed in Update or it can trigger multiple times within FixedUpdate.

    I am using the mouse click to trigger a raycast that needs to be sent from the proper camera position within FixedUpdate.

    Is there a workaround for this?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,717
    That is not true. Cinemachine needs to operate on the same clock that is being used to animate its targets. If your targets are moving on FixedUpdate, then CM needs to operate on FixedUpdate. If they are moving on Update, then CM needs to operate on LateUpdate. You will always get smoother results if you can get your targets to move on Update, and set CM to LateUpdate. One option, if you are using RigidBodies, is to turn Interpolation on.

    Even if your targets are moving on FixedUpdate, you can read input on Update and cache the result for use in FixedUpdate.
     
    TenEightCME likes this.