OVRのプレハブを利用して簡単につかむ機能を実装します。
- 単純な掴むの実装
- 離れた距離から掴むの実装(Distance Grab)
単純な掴むの実装
Player側の設定
とりあえず最初にPlayerControllerを設置します。

手として利用するプレハブはOculus/SampleFramework/Core/CustomHandsです。

必ずしもCustomHandsを利用する必要はありませんが、すべて揃っていて楽なのでこれを使います。
この右手と左手をLeftHandAnchorとRightHandAnchorにドロップします。

掴むのに重要なのはOVR Grabberスクリプトです。
赤線のPlayerObjectはOVRPlayerControllerを指定してください。
指定しない場合、掴んだオブジェクトとPlayerがぶつかるため、変な移動が発生します。
中身のコードは読んでませんが、Playerオブジェクトと掴んだオブジェクトの当たり判定を消していると思われます。
ParentTransformもNoneとなっていますが、実行時に自動的にCustomHandRight/Leftが割り当たるので設定しなくてもいいです。RightHandAnchor等を設定してもよいです。

掴まれる側の設定
適当にCube等のGameObjectを作成します。
これにOVR GrabbableスクリプトとRigidbodyを付与します。

掴まれる側はこれだけで終了です。
実行してみる
接触するほど接近して、Ouclusコントローラの握るボタン(中指)をホールドすれば掴むことができます。

コメント