GameObjectに物理法則(重力など)を付ける方法を紹介します。
GameObjectを準備
以下の画像のように床(Cube)と物理法則を付けるボール(Sphere)を準備する。

このままゲームを実行してもSphereは浮いたまま落ちてこない
ボール(Sphere)に物理法則を付ける
1.HierarchyタブでSphereを選択する

2.SphereのInspectorタブでAdd Componentをクリック。

3.検索窓で”rigid”と検索して出てくる”Rigidbody”を選択する。

完成
たったこれだけで、ゲームを実行すると物理の法則に基づいてボールが動作する。
例えば、重力が働いてボールが床に落ちるようになる。
ちなみに重力は、Rigidbodyの中のUse Gravityが該当する。
Use Gravityのチェックを外すと重力はなくなって、ボールは落ちなくなる。

コメント