障害物(GameObject)に当たったらカメラが振動するようにCinemachineを使ってやる方法です。
スクリプトを作る必要はなく簡単です。
※Cinemachineのインストール方法は記載してません。
完成動作
赤いGameObjectに触れたらカメラが振動しています。
作り方
1.シーンに各オブジェクトを配置
1-1.今回はunity-chanが赤いGameObject(Cylinder)に触れたらカメラが振動するので以下のように配置します。

2.Virtual Cameraを作成
2-1.”Cinemachine”→”Create Virtual Camera”を押下

2-2.”CM vcam1″が作成される。

3.”Virtual Camera”GameObjectの設定
3-1.”CM vcam1″の”Add Extension”プロパティで”Cinemachine Impulse Listener”を追加する。



4.障害物(Cylinder)の設定
4-1.当たったらカメラを振動させたいGameObject(今回はCylinder)に”Cinemachine Collision Impulse Source”コンポーネントをアタッチ


4-2.”Signal Shape”プロパティの値を”6D Shake”にする。
※”Raw Signal”の右端の⚙マークを押下して以下のように選択


4-3.揺れの大きさを適宜変更
”Ampituce Gain”や”Frequency Gain”の値を変えると揺れの大きさが変わる。今回は5にしてみた。

完成
これでunity-chanが障害物(Cylinder)に当たるとカメラが揺れる。
コメント
ブログを拝見しました、4-2.”Signal Shape”プロパティが現在のunityで出てこないのですが、これはどういう事でしょうか。。。unityバージョンは2021.2.7fで
Cinemachineは Version 2.8.4 – December 20, 2021です。
なにか変更があったのでしょうか。
申し訳ないですが、ご教授お願いします。
コメントありがとうございます。
その原因は、Cinemachineのバージョンのようです。
私のこの記事はVersion 2.6.11で行いました。
どのバージョンからかはわかりませんが、Version 2.8.4では”Cinemachine Collision Impulse Source”コンポーネントのプロパティに変更があったようです。
最新バージョンでのやり方だと、
“Cinemachine Collision Impulse Source”コンポーネントのプロパティの”Impulse Type”を”Legacy”にすると”Signal Shape”プロパティが出てくるので、それで設定できると思います。