Cinemachine Impulse not working

Hello everybody,

I’m trying to use the impulse system of Cinemachine, I tried everything I could think of and nothing even start to work.
I setup my cameras here :

// Add Cinemachine Brain
var cinemachineBrainObject = new GameObject("CinemachineBrain");
player.cinemachineBrain = cinemachineBrainObject.AddComponent<CinemachineBrain>();

// Ajoutez une caméra virtuelle concrète, pas la classe abstraite
player.cameraObject = new GameObject("CameraObject");
player.camera = player.cameraObject.AddComponent<Camera>();
player.cameraObject.transform.position = new Vector3(0, 5, -25);
player.cameraObject.transform.parent = pawn.pawnObject.transform;



player.cinemachineCamera = player.cameraObject.AddComponent<CinemachineCamera>();


player.cinemachineCamera.Follow = pawn.pawnObject.transform;
player.cinemachineCamera.LookAt = pawn.pawnObject.transform;

player.camera.fieldOfView = 110;

var followComp = player.cameraObject.AddComponent<CinemachineFollow>();
var rotationComp = player.cameraObject.AddComponent<CinemachineRotationComposer>();
var impulseListener = player.cameraObject.AddComponent<CinemachineImpulseListener>();

followComp.FollowOffset = new Vector3(0.0f,0.0f,-15.0f);
impulseListener.Gain = 1.0f;
impulseListener.ApplyAfter = CinemachineCore.Stage.Noise;
//impulseListener.ChannelMask = CinemachineChannelNames.Instance.

var impulseObject = new GameObject("impulseObject");
impulseObject.transform.parent = pawn.pawnObject.transform;
player.impulse = impulseObject.AddComponent<CinemachineImpulseSource>();

player.impulse.ImpulseDefinition = new CinemachineImpulseDefinition
{
    ImpulseType = CinemachineImpulseDefinition.ImpulseTypes.Uniform,
    ImpulseShape = CinemachineImpulseDefinition.ImpulseShapes.Explosion,
};

And I get those parameters when the game start :

I tried to change everything but I don’t have the beginning of a shake on my camera.
What am I doing wrong ?

Why are you creating all these things with script? Why not use the editor?

It appears that your gameobject hierarchy is incorrect. Cinemachine normally expects to be set up like this, with separate gameobjects, not parented to each other:

  1. Player gameobject (with your player controller script).
  2. Camera gameobject with CinemachineBrain and Camera component.
  3. CinemachineCamera gameobject, targeting Player. No Camera component on this.

You can have multiple objects of type 3, each encoding a different camera style. Activate them as necessary to change camera behaviour. CinemachineBrain will blend the main camera between them.

To make the camera shake, something needs to trigger the impulse event on the impulse source. Also, in the listener, you should have something in the Secondary Noise field, to make the camera shake in response to the impulse event.

Please look at some of the sample scenes that ship with Cinemachine. They will help you understand how it works.

Thanks for the help I will try that right away !

I’m doing all of this in code because I’m doing a project to learn ECS architecture, I’m using Arch ECS instead of the native ECS unity system.
My player isn’t really a gameObject, it’s an entity, everything is data oriented so I cannot really do stuff directly in the software. I can’t make an entity in the editor.

Making an entity look like that if you’re curious :

var player = pawnWorld.Create(
    new PawnComponent("Player"),
    new ECS.Component.HealthComponent(playerMaxLife, false),
    new PlayerComponent(playerSpeed, playerDodgeStrenght),
    new PositionComponent { X = 1f, Y = 1f },
    new VelocityComponent { dX = 0f, dY = 0f, minVelocity = 0, maxVelocity = playerSpeed },
    new AccelerationComponent { ddX = 0, ddY = 0 },
    new ShooterComponent(playerFireRate, playerFireRange, playerFirePower),
    new DisplayComponent("Sprites/PlayerSprite"),
    new CircleHitBoxComponent(playerHitboxRadius, playerHitboxLength, new Vector2(0f, 2.5f)),
    new CooldownComponent(
        new string[] { "ShootCD", "LaserCD", "SpriteAnimationCD", "AlucardCD", "DamageCD", "DeathCD", "DodgeCD", "DodgeDurationCD" },
        new float[] { playerFireRate, 0.2f, 0.5f, playerFireRate, 3f, 3f, playerDodgeCooldown, playerDodgeDuration },
        new bool[] { true, false, true, true, false, false, false, false }
        ),
    new ClampPosToArenaSizeComponent(arena),
    new AlucardGeneratorComponent(true, 1.0f, "#ff0070"),
    new SelfLightComponent(playerLightIntensity, playerLightRadius, playerLightColor)
    );

And it’s just data, the logic is handled with separate systems.

That worked thanks you so much.

1 Like