質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

Q&A

解決済

1回答

1141閲覧

アニメーションの座標がAnimationプレビューとPlay後で異なる

mushipan0929

総合スコア56

Unity3D

Unity3Dは、ゲームや対話式の3Dアプリケーション、トレーニングシュミレーション、そして医学的・建築学的な技術を可視化する、商業用の開発プラットフォームです。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

0グッド

0クリップ

投稿2022/02/24 07:47

編集2022/02/24 08:20

問題

アニメーションの座標がPlay後におかしくなる

説明

とあるアニメーションの座標がAnimationプレビューとPlay後で異なってしまいます。
Animationプレビュー
Play後 (想定よりも右にずれている)

補足

・プレイ時、rotationは(0,0,0)です。また、他のアニメーションも該当オブジェクトに影響は及ぼしません。

・Animatorで管理していますが、複数のアニメーションを同時再生したいので2つのレイヤーに分けています。
Body (Base Layer) / Bell (Additive / Weight: 1.0) ← Bell内に該当アニメーションが入っています。

・アニメーション遷移は Entry → 空アニメ →(※A) 該当アニメーション
→(※B) 空アニメ →(※A) 該当アニメーション...の流れになっています。
※A: HasExitTime: false, Conditions: isCalling=true (テスト段階なのでisCallingは常時true)
※B: HasExitTime: true, ExitTime: 1

調べてもお手上げな状態です。ご助力お願いいたします。

補足2

あれからベルを叩くアニメーションをBodyレイヤーに、その他のアニメーションをBellレイヤーに
移動する事でどちらも問題なく動きましたが、依然問題が不明なので質問は締めません。

私のレイヤーの使い方が間違っているのかもしれないので、その辺りを中心に調べてみます。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

ご説明いただいた手順をまねてアニメーションを作ってみたところ、確かにずれた位置を中心にハンマーが振動しました。

図1

この現象については、ちょっと調査不十分で不確かではあるのですが、「AnimationUtility-SetAdditiveReferencePose - Unity スクリプトリファレンス」にある...

By default, an animation clip used in an additive layer uses the pose at time 0 as its reference pose.

との記述が関係あるかもしれません。今回のアニメーションクリップは最初のフレームでハンマーが最大に傾いた状態になっていますので、そこが基準姿勢だということになってしまったんでしょうかね...?
あの項目は外部ソフトで作成したアニメーションの場合はインポート設定のクリップ固有のプロパティとして設定できるようなのですが、Unity上で作成したアニメーションの場合はどうすればいいのかわからず、仕方ないのでEditorフォルダを作って下記スクリプトを入れ...

C#

1using UnityEditor; 2using UnityEngine; 3 4public class ReferencePoseConfigurator : EditorWindow 5{ 6 private AnimationClip clip; 7 private AnimationClip referenceClip; 8 private float clipLength; 9 private int clipFrameCount; 10 private float time; 11 private int frame; 12 private float modifiedTime; 13 private int modifiedFrame; 14 private ConfigurationMode configurationMode; 15 16 private void OnGUI() 17 { 18 if (this.clip == null) 19 { 20 EditorGUILayout.HelpBox("No clip selected.", MessageType.Error); 21 return; 22 } 23 EditorGUILayout.LabelField("Name", this.clip.name); 24 if (this.referenceClip != this.clip) 25 { 26 EditorGUILayout.HelpBox( 27 $"This clip refers to another clip \"{this.referenceClip!.name}\" as the reference pose source. This is not supported.", 28 MessageType.Error); 29 return; 30 } 31 this.configurationMode = (ConfigurationMode)EditorGUILayout.EnumPopup("Set by", this.configurationMode)!; 32 if (this.configurationMode == ConfigurationMode.Frame) 33 { 34 this.modifiedFrame = EditorGUILayout.IntSlider( 35 "Reference Frame", 36 this.modifiedFrame, 37 0, 38 this.clipFrameCount); 39 this.modifiedTime = this.modifiedFrame / this.clip.frameRate; 40 } 41 else 42 { 43 this.modifiedTime = EditorGUILayout.Slider("Reference Time", this.modifiedTime, 0, this.clipLength); 44 this.modifiedFrame = Mathf.RoundToInt(this.modifiedTime * this.clip.frameRate); 45 } 46 using (new EditorGUI.DisabledScope(this.modifiedTime == this.time)) 47 { 48 if (GUILayout.Button("Apply")) 49 { 50 this.time = this.modifiedTime; 51 this.frame = this.modifiedFrame; 52 Undo.RecordObject(this.clip, "Set Additive Reference Pose"); 53 AnimationUtility.SetAdditiveReferencePose(this.clip, this.clip, this.time); 54 } 55 } 56 } 57 58 private void OnSelectionChange() 59 { 60 this.ReadClipData(); 61 this.Repaint(); 62 } 63 64 private void ReadClipData() 65 { 66 this.clip = Selection.activeObject as AnimationClip; 67 if (this.clip == null) 68 { 69 return; 70 } 71 var currentSettings = AnimationUtility.GetAnimationClipSettings(this.clip); 72 this.referenceClip = currentSettings!.additiveReferencePoseClip; 73 if (this.referenceClip == null) 74 { 75 this.referenceClip = this.clip; 76 } 77 if (this.referenceClip != this.clip) 78 { 79 return; 80 } 81 this.clipLength = this.clip.length; 82 this.clipFrameCount = Mathf.RoundToInt(this.clipLength * this.clip.frameRate); 83 this.time = currentSettings.additiveReferencePoseTime; 84 this.frame = Mathf.RoundToInt(this.time * this.clip.frameRate); 85 this.modifiedTime = this.time; 86 this.modifiedFrame = this.frame; 87 } 88 89 [MenuItem("Utility/Animation/Configure Reference Pose")] 90 private static void Init() 91 { 92 var window = GetWindow<ReferencePoseConfigurator>()!; 93 window.titleContent = new GUIContent("Configure Reference Pose"); 94 window.ReadClipData(); 95 window.Show(); 96 } 97 98 private enum ConfigurationMode 99 { 100 Time, 101 Frame 102 } 103}

メニューに追加された「Utility」→「Animation」→「Configure Reference Pose」で設定ウィンドウを開き、ベルのアニメーションクリップを選択して、ハンマーが中心に到達する2フレーム目を基準姿勢にするよう設定したところ...

図2

どうやら中心を基準に振動するようになったようでした。

図3

投稿2022/02/27 00:12

Bongo

総合スコア10807

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

mushipan0929

2022/02/27 03:53

状況再現まで行って頂きありがとうございます。 > By default, an animation clip used in an additive layer uses the pose at time 0 as its reference pose. 確かに初期Rotationを調整したところ正しく動作しました。 私はまだUnity拡張に手を出していないので、現状回答者様のスクリプトはオーパーツではありますが 少しずつ読み解いていこうと思います、ご丁寧な回答ありがとうございました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問