【Unity】オブジェクトの加速度を簡単に取得する
2020-04-03
Steam VR Pluginに含まれているVelocityEstimatorを利用する方法.
ちなみに加速度は距離を微分したら速度が得られて,距離を2回微分したら加速度を得られるわけであって…
Env.
Unity 2019.3.3f1
Windows10 64bit
Method
Unity Asset StoreからSteam VR Pluginをダウンロードし,中に含まれるVelocityEstimator.csを拝借する.
https://assetstore.unity.com/packages/tools/integration/steamvr-plugin-32647
加速度を取得したいオブジェクトにVelocityEstimatorをアタッチし,
BeginEstimatingVelocity() で加速度や速度を算出し始め,FinishEstimatingVelocity() で算出を終了する.
Estimate On Awakeにチェックを入れておくとAwakeでBeginEstimatingVelocity() が呼ばれるようになる.
GetAccelerationEstimate() で加速度を取得できる.
また,GetVelocityEstimate() で現在の速度,GetAngularVelocityEstimate() で角速度を取得できる.
どのくらい正確なのかは分からないが,便利.