まずtransform.forwardについては、https://github.com/Unity-Technologies/UnityCsReference/blob/master/Runtime/Transform/ScriptBindings/Transform.bindings.cs 内に...
// The blue axis of the transform in world space.
public Vector3 forward { get { return rotation * Vector3.forward; } set { rotation = Quaternion.LookRotation(value); } }
との記述がありましたので、回答中で申し上げた「TransformDirectionは回転だけを考慮する」という予想が合っていれば「this.transform.forward」と「this.transform.TransformDirection(Vector3.forward)」は同等(実験結果ではわずかに誤差が発生しているため、まったく同じ計算プロセスを経ているのではなさそうでしたので「同じ」と言い切るのは避けました)、そしてその逆の「Vector3.forward」と「this.transform.InverseTransformDirection(this.transform.forward)」も同等と言ってよさそうです。
次に、ワールド座標系ベクトルを使いTranslateのrelativeToを省略してSpace.Selfで同等の動きをさせる、およびローカル座標系ベクトルを使いSpace.Worldで同等の動きをさせる件についてですが、これもどちらも問題なさそうです。
Transform.bindings.cs内では...
// Moves the transform in the direction and distance of /translation/.
public void Translate(Vector3 translation, [UnityEngine.Internal.DefaultValue("Space.Self")] Space relativeTo)
{
if (relativeTo == Space.World)
position += translation;
else
position += TransformDirection(translation);
}
となっており、Space.Selfの場合は引数のtranslationをTransformDirectionで変換してpositionに加算しているようでした。ですので、おっしゃる通りtranslationをあらかじめTransformDirectionで変換してからTranslateをSpace.Worldで実行すればSpace.Selfの時と同等になるでしょうし、逆にあらかじめtranslationをInverseTransformDirectionで逆変換してからTranslateをSpace.Selfで実行すれば、translationがメソッド内のTransformDirectionによりワールド座標系のベクトルに変わり、Space.Worldの時と同等になると言えそうです。
※最後に一つお詫びしますが、回答中のコードのStart内での実験の部分で、Y基底とZ基底のなす角度をコンソールに出力する部分の見出しが「Direction X-Z angle:」、「Vector X-Z angle:」になっていました。
実験自体に影響する部分ではないですが、正しい見出しは「Direction Y-Z angle:」、「Vector Y-Z angle:」となります。すみません...
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/04/25 19:26
2019/04/25 20:35
退会済みユーザー
2019/04/26 13:59
2019/04/26 22:24 編集
退会済みユーザー
2019/04/27 00:16