【3Dゲームエンジン】Unity質問スレッド32 at GAMEDEV【3Dゲームエンジン】Unity質問スレッド32 - 暇つぶし2ch■コピペモード□スレを通常表示□オプションモード□このスレッドのURL■項目テキスト1024:名前は開発中のものです。 17/12/20 00:39:41.23 TUVA4DF6.net ①Quaternion.FromToRotationを使用する方法1 transform.rotation = Quaternion.FromToRotation (Vector3.right, direction); ②Quaternion.FromToRotationを使用する方法2 transform.rotation = transform.rotation * Quaternion.FromToRotation (transform.right, direction); ③Vector3.Angleを使用する方法1 transform.rotation = Quaternion.Euler(0, 0, Mathf.Sign(Vector3.Dot(Vector3.forward, Vector3.Cross(Vector3.right, direction))) *Vector3.Angle(Vector3.right, direction)); ④Vector3.Angleを使用する方法2 transform.rotation = transform.rotation * Quaternion.Euler(0, 0, Mathf.Sign(Vector3.Dot(transform.forward, Vector3.Cross(transform.right, direction))) *Vector3.Angle(transform.right, direction)); 1025:名前は開発中のものです。 17/12/20 00:44:36.57 TUVA4DF6.net ⑤Vector3.Angleを使用する方法3(Rotateを使用) transform.Rotate (0, 0, Mathf.Sign(Vector3.Dot(Vector3.forward, Vector3.Cross(transform.right, direction))) *Vector3.Angle(transform.right, direction)); ⑥Mathf.Atan2を使用する方法1(Rotateを使用) transform.Rotate (0, 0, Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg - transform.rotation.eulerAngles.z); ⑦Mathf.Atan2を使用する方法2 transform.rotation = Quaternion.AngleAxis(Mathf.Atan2((direction.y, direction.x) * Mathf.Rad2Deg, Vector3.forward); うーん、どうやっても元よりも長いコードになってしまいます。 オブジェクトAの位置が原点だとか、オブジェクトAの向きが無回転だとか、 条件を付ければ、もう少し簡略化できますが・・・ 次ページ最新レス表示レスジャンプ類似スレ一覧スレッドの検索話題のニュースおまかせリストオプションしおりを挟むスレッドに書込スレッドの一覧暇つぶし2ch