フリー版で開発したゲームは個人・法人を問わず追加のロイヤリティーなしで販売できます。
プラットフォームサポートはiPhone/iPod Touch/iPad、Mac、PC、Web、Wii、Xbox360、Android、PlayStation 3、PlayStation 4、PS Vita他
次スレは>>950以降にできるだけ早く(できれば回答者が回答した後にでも余裕を持って)建てて下さい。
■Unity 2ch Wiki(まとめ、過去ログ、リンク集)
http://www24.atwiki.jp/unity2ch/
●リンク
・Unity(日本公式サイト)
http://unity3d.com/jp
・マニュアル
http://docs.unity3d.com/ja/current/Manual/index.html
・チュートリアル
http://unity3d.com/jp/learn/tutorials
・スクリプトリファレンス
http://docs.unity3d.com/ja/current/ScriptReference/index.html
・FAQ
http://unity3d.com/jp/unity/faq
・MSDN
http://msdn.microsoft.com/ja-jp/ms348103←スクリプトのエラー番号をこれで検索すると原因が日本語で出てきます。
前スレ
【3Dゲームエンジン】Unity質問スレッド31
https://mevius.5ch.net/test/read.cgi/gamedev/1504366121/
探検
【3Dゲームエンジン】Unity質問スレッド32
レス数が950を超えています。1000を超えると書き込みができなくなります。
1名無し@キムチ
2017/10/30(月) 05:05:35.00ID:xnHTCaF3976名前は開発中のものです。
2017/12/20(水) 00:34:43.35ID:TUVA4DF6 >>969
考えてみました。
Aに下記のスクリプトをセットします。
public class A : MonoBehaviour {
GameObject obj;
Vector3 target, position, direction;
void Start () {
obj = GameObject.Find ("B");
target = obj.transform.position;
position = transform.position;
direction = target - position;
Invoke ("Rotate", 1.0f);
}
void Rotate(){
transform.right = direction; ←ここを置き換えるコードです。
}
}
考えてみました。
Aに下記のスクリプトをセットします。
public class A : MonoBehaviour {
GameObject obj;
Vector3 target, position, direction;
void Start () {
obj = GameObject.Find ("B");
target = obj.transform.position;
position = transform.position;
direction = target - position;
Invoke ("Rotate", 1.0f);
}
void Rotate(){
transform.right = direction; ←ここを置き換えるコードです。
}
}
977名前は開発中のものです。
2017/12/20(水) 00:39:41.23ID:TUVA4DF6 @Quaternion.FromToRotationを使用する方法1
transform.rotation = Quaternion.FromToRotation (Vector3.right, direction);
AQuaternion.FromToRotationを使用する方法2
transform.rotation = transform.rotation * Quaternion.FromToRotation (transform.right, direction);
BVector3.Angleを使用する方法1
transform.rotation = Quaternion.Euler(0, 0, Mathf.Sign(Vector3.Dot(Vector3.forward, Vector3.Cross(Vector3.right, direction))) *Vector3.Angle(Vector3.right, direction));
CVector3.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));
transform.rotation = Quaternion.FromToRotation (Vector3.right, direction);
AQuaternion.FromToRotationを使用する方法2
transform.rotation = transform.rotation * Quaternion.FromToRotation (transform.right, direction);
BVector3.Angleを使用する方法1
transform.rotation = Quaternion.Euler(0, 0, Mathf.Sign(Vector3.Dot(Vector3.forward, Vector3.Cross(Vector3.right, direction))) *Vector3.Angle(Vector3.right, direction));
CVector3.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));
978名前は開発中のものです。
2017/12/20(水) 00:44:36.57ID:TUVA4DF6 DVector3.Angleを使用する方法3(Rotateを使用)
transform.Rotate (0, 0, Mathf.Sign(Vector3.Dot(Vector3.forward, Vector3.Cross(transform.right, direction))) *Vector3.Angle(transform.right, direction));
EMathf.Atan2を使用する方法1(Rotateを使用)
transform.Rotate (0, 0, Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg - transform.rotation.eulerAngles.z);
FMathf.Atan2を使用する方法2
transform.rotation = Quaternion.AngleAxis(Mathf.Atan2((direction.y, direction.x) * Mathf.Rad2Deg, Vector3.forward);
うーん、どうやっても元よりも長いコードになってしまいます。
オブジェクトAの位置が原点だとか、オブジェクトAの向きが無回転だとか、
条件を付ければ、もう少し簡略化できますが・・・
transform.Rotate (0, 0, Mathf.Sign(Vector3.Dot(Vector3.forward, Vector3.Cross(transform.right, direction))) *Vector3.Angle(transform.right, direction));
EMathf.Atan2を使用する方法1(Rotateを使用)
transform.Rotate (0, 0, Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg - transform.rotation.eulerAngles.z);
FMathf.Atan2を使用する方法2
transform.rotation = Quaternion.AngleAxis(Mathf.Atan2((direction.y, direction.x) * Mathf.Rad2Deg, Vector3.forward);
うーん、どうやっても元よりも長いコードになってしまいます。
オブジェクトAの位置が原点だとか、オブジェクトAの向きが無回転だとか、
条件を付ければ、もう少し簡略化できますが・・・
979名前は開発中のものです。
2017/12/20(水) 01:00:49.24ID:TUVA4DF6 Quaternion.FromToRotation(A, B)では、
回転方向を含めた回転状態を得られますが、
Vector3.Angle(A, B)では、
ベクトル間の角度しかわからず、向きがわかりません。
また、取得される角度は180度以下に限定されるため、
左向きに270度は、右向きに90度かもしれないということです。
回転方向は、Vector3.Cross(A, B)のZ成分が正か負かで判定します。
2Dでは、Mathf.Sign((Vector3.Cross(A, B)).z)でも良いのですが、
3Dでは、回転面がXY平面上とは限らないため、外積ベクトルと
正の向きにしたい軸との内積をとってから符号判定した方が確実です。
Atan2関数は、戻り値がradのため、度に直す必要があります。
また、相対回転であるRotateを使用する場合は、
求めた偏角から、現在の向きの回転角を引いておく必要があります。
rotationはQuaternionのため、eulerAnglesでオイラー角に戻しておき、
Z軸回転成分だけを取り出して減算します。
回転方向を含めた回転状態を得られますが、
Vector3.Angle(A, B)では、
ベクトル間の角度しかわからず、向きがわかりません。
また、取得される角度は180度以下に限定されるため、
左向きに270度は、右向きに90度かもしれないということです。
回転方向は、Vector3.Cross(A, B)のZ成分が正か負かで判定します。
2Dでは、Mathf.Sign((Vector3.Cross(A, B)).z)でも良いのですが、
3Dでは、回転面がXY平面上とは限らないため、外積ベクトルと
正の向きにしたい軸との内積をとってから符号判定した方が確実です。
Atan2関数は、戻り値がradのため、度に直す必要があります。
また、相対回転であるRotateを使用する場合は、
求めた偏角から、現在の向きの回転角を引いておく必要があります。
rotationはQuaternionのため、eulerAnglesでオイラー角に戻しておき、
Z軸回転成分だけを取り出して減算します。
レス数が950を超えています。1000を超えると書き込みができなくなります。
ニュース
- バリ島で男子生徒ら集団万引きか、防犯カメラ映像が拡散 京都の大谷中学・高校が「窃盗行為」謝罪★4 [七波羅探題★]
- 中国軍機レーダー照射、トランプ氏沈黙突く 試される日本外交 [蚤の市★]
- 【地震】青森県で震度6強 長周期地震動も 津波注意報すべて解除 ★7 [ぐれ★] [ぐれ★]
- トランプ大統領 エヌビディア製AI半導体の中国輸出許可 安全保障重視の方針転換 [蚤の市★]
- 【広島】「万引きした人を追跡」コンビニ店員の男性(46)を果物ナイフで刺したか 中国籍の少年(17)を殺人未遂容疑で現行犯逮捕 [ぐれ★]
- 【芸能】デヴィ夫人「日本では犬猫は器物。動物保護を何とか立法化したい」 人と動物が共生を力強く訴え [冬月記者★]
- 【画像】TOKIO山口達也に「いいべ」された当時のJK、性加害の反動であたしこグラドルにwww [779857986]
- 寒さしのげる場所があって食べ物も豊富にあるなら熊は冬眠しないの?
- 声優・矢尾一樹の妻「治療の影響で思う様に話せない彼に、近くで仕事をしてきた人が、かっこ悪い!もう辞めなよと言った。私は許さない」 [594040874]
- 気象庁・高市内閣「この後311級の地震の可能性があります。北海道〜関東の人は1週間は地震が来てもすぐ逃げられる格好をしてください」 [597533159]
- 【悲報】高市早苗の擬人化がXで大バズりwwwwwwwwwwww [455031798]
- こんぺこ!こんぺこ!こんぺこ!🐰🏡
