How do I set up camera shake during an explosion with Cinemachine? This is the first time that I've messed with the impulse listener on cinemachine and so far, I can only get the camera to shake when the an object makes a collision with the object that the 'Cinemachine Collision Impulse Source' component is attached to(in my case, a Grenade). I want to set it up so that the camera will only shake at the moment the grenade explodes(Because my Grenade script has a countdown timer before it explodes, it does not just explode upon collision).
1 Answer
Use the Cinemachine Impulse Source component to generate impulses on events that are not collisions or Collider triggers. This is a generic Impulse Source that exposes a family of GenerateImpulse() API methods. These methods generate impulses at the specified locations and with the specified velocities and strengths. Call these methods directly from your game logic, or use them with UnityEvents.
So, place an Impulse Source component somewhere in your scene. It can be part of the explosion effect prefab you spawn on demand, or a persistent scene object that you trigger at the same time you spawn the explosion.
Make sure its range/dissipation distance is quite large, so your camera can "hear" the explosion from a long distance away.
To cause the shake, call one of this component's GenerateImpulse()
methods, or GenerateImpulseAt(position of explosion, Vector3.up)
if the component is attached to an object away from the actual explosion site.
-
\$\begingroup\$ This is appreciated, nice! It works perfectly! \$\endgroup\$ Aug 11, 2020 at 7:51
-
\$\begingroup\$ Don't forget to check the documentation — I've never used Cinemachine, so this answer was just a 30-second web search. \$\endgroup\$– DMGregory ♦Aug 11, 2020 at 10:14