What about selecting the right Impulse Source?

Now, when adding the second impulse source it had been mentioned, that it is indeed another one on the player, and that it’s fine to have more than one with different settings.
The second one is an explosion (kust like the other one) just with somewhat different values.

But in the script we just grab a impulse source and never verify we got the one we wanted. I would believe we get the first one, so just the one we already had before.

(And I think the end of the lesson does show the shakes to be more powerful than what had been shown before when testing the settings…)

Now, how to we tell which of the impulse sources we’ve got (or rather how do we specifiy which one to get)? I would think part of the solution would be the “Impulse Channel” setting. I guess we can get both of the sources and then chose the one we want from the list of components that we get in a GetComponents<CinemachineImpulseSource>(), and the way to do that might be iterating over the list and check for the channel?

1 Like

Thanks heckert, you actually gave me an idea on how to continue, as the collision trigger was actually sending the event to the wrong impulse. By using GetComponents, I could just specify which one was the one I wanted to trigger (no need for iterating or checking channels)

CinemachineImpulseSource[] _impulseSources;

private void Awake() {
    _rigidBody = GetComponent<Rigidbody2D>();
    _impulseSources = GetComponents<CinemachineImpulseSource>();

private void OnCollisionEnter2D(Collision2D collision) {
    if(_velocityBeforePhysicsUpdate.y < _yLandVelocityCheck) {
1 Like

I’m sure it works, but the index for the selection is hard coded, which would be a fragile connection. If there were even more different impulses one wanted to trigger, this could be difficult to handle pretty soon…

I’ve highlighted this question to Stephen as we probably should be checking we are getting the correct impulse source.

1 Like

Actually a pretty big oversight on my part! Suprised it slipped through my fingers! I’ll have to go add a little diddy into a lecture somewhere. But the way I would typically tackle it is likely just a serializedfield and assign which ever impulse source I wanted to fire.


With the scope of this game project, just connecting the component by using a serialized field sounds about right. :slight_smile:

I would love to see some example on how to make use of those channels, though :wink:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms