Search Unity

Cinemachine Impulse Listener on player object?

Discussion in 'Cinemachine' started by zt3ff3n, Jul 4, 2018.

  1. zt3ff3n

    zt3ff3n

    Joined:
    Feb 19, 2016
    Posts:
    37
    I'm using the freelook rig as a mainly top-down camera looking at my player-object from a higher Y-axis offset.
    I'd still like it to shake whenever the player shoots, is close to an explosion etc. I can only seem to attach the Impulse Listener onto the virtual camera, which makes it shake if the camera is close to an explosion etc. How do I go about controlling the shake with the magnitude an all that lovely juice - only based impulses near the player-object?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    You can do it very easily with a custom impulse Listener.

    Find CinemachineImpulseListener.cs, copy it into your Assets folder, and rename it to ImpulseListenerAtTarget, or something like that. Rename the class name to match.

    Then, look inside where it calls CinemachineImpulseManager.Instance.GetImpulseAt(), and instead of passing it State.FinalPosition as the listener location, change it to pass it the player's position. Use the new extension in place of CinemachineImpulseListener, and you will get the behaviour you're looking for.
     
  3. zt3ff3n

    zt3ff3n

    Joined:
    Feb 19, 2016
    Posts:
    37
    Thanks Greg!
     
  4. Rafaelski

    Rafaelski

    Joined:
    May 1, 2019
    Posts:
    12
    Hello!
    How could I use the Cinemachine Impulse Listener in a GameObject that is not a virtual camera, so it can shake with the impulse Collision?

    I saw that this is possible at this video:


    But I could'nt find a way to make this work.
     
  5. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Attach a CinemachineIndependentImpulseListener to the gameobject