• RuntimesUnity
  • rootmotionの正しい使い方を知りたい / How to make rootmotion work as expected

Related Discussions
...

また、もう一つすみません。

koyu2 ---■ 親ボーンのスケールの影響を受けない
コンストレイントをスキンに組み込み、体型の異なるキャラを実装しています。
rootmotionに指定したボーンは親のスケール縮小によって移動距離が調整されます

基準となっている男性は問題なく前進しながら攻撃します。
しかしスケールが小さくなったゴブリンはモーションが完了する度に前に瞬間移動してしまいます。
親ボーンのスケール縮小は考慮されないのでしょうか?

最初の投稿の2番目の疑問なのですが、
rootmotionの移動量をボーンのローカル座標ではなく、ワールド座標を参照する方法はないものでしょうか?
もし現在その方法がなければ、将来的にワールド座標でrootmotionの移動ができるようになってほしいと思っています。
理由としては、異なる体型の移動量の違いを表現できず、下記の動画のように別の体型のキャラクターが瞬間移動してしまうからです

この異なる体型をスキンを用いて実装する手法はSpine公式のやり方を参考にしています
https://ja.esotericsoftware.com/blog/Skin-constraints-for-different-proportions

RootMotionの移動量をSpineエディタ上のワールド座標で取得することができれば、この瞬間移動の問題は解消され、異なる体型毎にアニメを用意する必要がなくなります。
ご検討いただけると嬉しいです。

    koyu2 最初の投稿の2番目の疑問なのですが、
    rootmotionの移動量をボーンのローカル座標ではなく、ワールド座標を参照する方法はないものでしょうか?
    もし現在その方法がなければ、将来的にワールド座標でrootmotionの移動ができるようになってほしいと思っています。

    Sorry, the RootMotion components sample the animation timelines and support only local-space rootmotion. In general it should not be necessary to support skeleton-space root motion (and it would potentially create problems due to feedback effects). Do you have a setup where the parent of the root-motion bone is moving or scaling? If so, why?

    koyu2 理由としては、異なる体型の移動量の違いを表現できず、下記の動画のように別の体型のキャラクターが瞬間移動してしまうからです
    The reason is that it is not possible to express the difference in the amount of movement between different body types, and characters with different body types will move instantaneously, as shown in the video below.

    Unfortunately I don't understand the problem from your video. What does your bone hierarchy setup look like that that's a problem? Please always share some screenshots of the setup of your skeleton or components if things go wrong, not just a video of the undesired result. Note that we have no idea how your two characters are setup, what is common and where they differ.

    @koyu2 Unfortunately me tests have concluded the rigidbody2D.MovePosition can't reliably be replaced by setting (or adding) rigidbody2D.velocity.

    A longer explanation:
    MovePosition seems to be the only precise and reliable way to set movement delta, for both 2D and 3D rigidbodies. Setting velocity like "rigidBody2D.velocity = movement/deltaTime" works perfectly in mid-air
    without gravity and ground collision, unfortunately when on the ground, friction causes severe slowdown. Using a zero-friction PhysicsMaterial leads to sliding endlessly along the ground as soon as forces are applied. Additionally, there is no rigidBody2D.isGrounded, requiring our own checks.

    So the best workaround to apply your own forces and velocities is to write your own scripts where you can add forces, set velocities, apply your own drag, etc. Then each frame you can calculate the resulting movement for this frame and assign the value at rootMotion.AdditionalRigidbody2DMovement = movementThisFrame.

      Harald

      Do you have a setup where the parent of the root-motion bone is moving or scaling? If so, why?

      はい。私のroot-motion boneは親のスケールの影響を受けています。
      なぜそうするのか? 異なる体型に合わせて、rootmotionの移動量も適切な位置に(Spineエディタ上では)自動的に調整できたからです。

      このように、rootmotion に必要な「.root_move-」ボーンは「bodysize_all」ボーンの子に配置されています。「bodysize_all」ボーンはスキンに割り当てられたコンストレイントの影響を受けスケールが縮小します
      .

      ゴブリンのスキンを有効にすると、このようにbodysizeボーンがスケール縮小し、体型が変わります。
      このスケルトンでRootmotionを用いて作った前進攻撃のアニメが以下の動画です
      .

      root_move ボーンの位置を見てください。これは同一のアニメですが、スケール縮小の影響を受けるため、rootmoveボーンがどちらも適切な股下の位置に移動しています。
      root_moveボーンをRootmotionに適用すれば、一見問題なく異なる移動量を実現できそうです。

      しかし、残念ながらUnityランタイムのRootMotionはローカルの移動量しか計算しません。
      エディタ上で適切に見えるrootmotionの移動量は実際には下記の画像の位置で計算されています。
      .

      スケール縮小が考慮されなくなった分、実際の移動量より前にroot_moveボーンが移動しています。
      それはRootMotionの移動量に対してSpineグラフィック上の移動量が足りないことを意味します。
      そのためアニメが遷移した際、前の投稿で示した動画のような瞬間移動が起こります。

      Spineは公式ブログで異なる体型の実装テクニックを紹介しています。
      しかし、現在Rootmotionはエディタ上のワールド位置ではなく、ローカル移動量しか計算しないため、Rootmotionと上記のテクニックを併用することができません。
      そのためrootmotionの移動量を調整したアニメを体型の数だけ用意しなければならないケースに直面します。異なる体型が5つあった場合、rootmotionを使用したアニメの数が5倍になります。

      また、Rootmotionがワールド位置を参照できた場合、Rootmotionボーンとhipボーンをコンストレイントしてボーン移動を自動化できるかもしれません。

      以上がRootmotionがワールド位置を参照してくれるようになってほしい理由です
      ここまで読んでくださりありがとうございます。

      Harald

      Unfortunately me tests have concluded the rigidbody2D.MovePosition can't reliably be replaced by setting (or adding) rigidbody2D.velocity.
      Then each frame you can calculate the resulting movement for this frame and assign the value at rootMotion.AdditionalRigidbody2DMovement = movementThisFrame.

      了解です!velocityとAddforceでの移動が難しい旨、承知しました。
      教えていただいたrootMotion.AdditionalRigidbody2DMovementを使用して物理挙動の再現を試してみたいと思います

      あなたのご尽力に感謝します!

      @koyu2 Thanks for the detailed writeup. Sorry, my previous answer was actually not entirely correct regarding skeleton space vs local space root motion: Parent bone scale is supported, as it looks like you're using in your skeleton setup. What is not supported is rotation in the parent bones combined with scale and the like. If a simply scaled parent bone breaks root-motion, there might be a bug in the spine-unity runtime.

      I just noticed that your description already contains the likely source of the problem:

      The "bodysize_all" bone is scaled down by the constraint assigned to the skin

      Currently only transform constraints are respected and applied if they are targeting the root bone, but not constraints scaling parents of the root-motion bone.
      This is a valid scenario, so we would like to fix this issue. Could you please send us the problematic skeleton assets which has a scaled parent above the root motion bone? Alterantively you could also send us a minimal Unity project again with this skeleton asset.

        Harald
        こんにちはハラルドさん。
        ご対応ありがとうございます!
        先ほどSpineのプロジェクトをメールアドレスに送信しました!
        最小限のUnityプロジェクトも同梱されています。

        ご査収頂けますと幸いです。

        Thanks for sending the reproduction project, we received everything. We will get back to you here on the forum once we have a bugfix ready.

        こんにちは、ハラルドさん。
        ランタイムの更新ありがとうございます。

        新しいSpine-Unity4.2のパッケージをインポートして確認しました。
        体型の異なるキャラクターの瞬間移動問題が解消されました!
        スムーズなアニメ遷移が実現できて嬉しく思います。

        この度はご対応くださってありがとうございます!

        @koyu2 Very glad to hear, thanks for letting us know. Also thanks again for reporting this issue!