2ちゃんねる スマホ用 ■掲示板に戻る■ 全部 1- 最新50    

■ このスレッドは過去ログ倉庫に格納されています

【3Dゲームエンジン】Unity質問スレッド17

1 :名前は開発中のものです。:2015/04/19(日) 12:16:54.53 ID:Erl+lZnN.net
3Dゲームエンジン「Unity」の質問に優しく答えるスレです。
Windows/Mac用。JavaScript/C#/Booといった汎用言語を使用できるのが特徴です。
フリー版で開発したゲームは個人・法人を問わず追加のロイヤリティーなしで販売できます。
プラットフォームサポートはiPhone/iPod Touch/iPad、Mac、PC、Web、Wii、Xbox360、Android、PlayStation 3、PlayStation 4、PS Vita他

次スレは>>970を踏んだ方が建てること。ダメなら>>980>>990が建てて下さい。

■前スレ
【3Dゲームエンジン】Unity質問スレッド16
http://peace.2ch.net/test/read.cgi/gamedev/1425192691/

■本スレ
【3Dゲームエンジン】Unity総合スレッド26
http://peace.2ch.net/test/read.cgi/gamedev/1429375487/

■Unity 2ch Wiki(まとめ、過去ログ、リンク集)
http://www24.atwiki.jp/unity2ch/

●リンク
・Unity(日本公式サイト)
 http://unity3d.com/japan/
・ユーザーガイド&リファレンス
 http://japan.unity3d.com/developer/document/
・チュートリアル
 http://japan.unity3d.com/developer/document/tutorial/
・スクリプトリファレンス
 http://docs-jp.unity3d.com/Documentation/ScriptReference/
・FAQ
 http://answers.unity3d.com/index.html
・MSDN
 http://msdn.microsoft.com/ja-jp/ms348103←スクリプトのエラー番号をこれで検索すると原因が日本語で出てきます。
注意事項:アセットおじさんは優しく愛でましょう

961 :名前は開発中のものです。:2015/06/12(金) 11:53:07.30 ID:hWrk7D/h.net
>>958
Entryはステートマシンに入ったときに分岐させるためのステート、じゃなかったか?

>>959
RigidBodyって何かっていうと
物理エンジンにしたがって自動でTransformを動かすコンポーネント、
な訳だがこれはFixedUpdate()の周期で動作する。
だから物理エンジンがらみのものはFixedUpdate()に書く。

カクつかなかった理由はわからん。カクツキが生じる理由は
複数考えられるので処理を全部見なければ特定しようがない。

>>960
そもそもMinMaxの設定値がキャラの大きさとか考慮しきれてないのではないか
あとUpdate()はFixedUpdate()と違った周期で実行されていて壁へのめりこみを
自動で押し返す機能を持ったRigidBodyはFixedUpdate()の周期で実行されているので
FixedUpdate()でRigidBodyが押し返す→Update()で壁にめり込ませている
ということに恐らくなってる。
正確にはRigidBodyの処理はFixedUpdate()の直後に実行されているはず
http://docs.unity3d.com/Manual/ExecutionOrder.html

962 :名前は開発中のものです。:2015/06/12(金) 12:19:08.13 ID:ESSmrvBP.net
今日はUnityにも通じているA級エスパーさんが頑張ってくれているとはいえ
質問は他人にも内容が理解できた方が好ましいから質問者は気をつけるようにな

963 :名前は開発中のものです。:2015/06/12(金) 13:36:16.27 ID:p4RcDMh7.net
>>954ですが
状態マシンを使って、タイトルシーンで
public class Title : State{
float timer; float wait = 2.0f;
public StateManager manager;
pubic Title(StateManager SM){
manager = SM;
}
public void StateUpdate{
timer += Time.deltaTime:
if(timer >= wait){
TitleAction();
}
if(Input.anykey){
Application.Loadlevel(”Play”);
Time.timeScale = 1;
manager.Switch(new Play(manager) )
}
}
と言った感じでするとプレイシーンで
public class Play : State{
publc Transform moviePoint;
publc Transform startPoint;
public float speed = 1.0f;
public StateManager manager;
pubic Play(StateManager SM){
manager = SM;
}
void StateUpdate(){
transform.position = Vector3.Lerp(moviePoint.position, startPoint.position, Time.deltaTime * speed)
}}と言った物ですが、Lerpが途中の位置から始まってしまう挙動となってます

964 :名前は開発中のものです。:2015/06/12(金) 13:45:43.88 ID:6d9MVPBA.net
お前のオツムが弱くて理解出来なかったからって
悔しがんなよ

965 :名前は開発中のものです。:2015/06/12(金) 13:46:13.08 ID:/NdS7CrW.net
>>959
Updateは負荷によって間引かれる(フレーム落ち)が、FixedUpdateは基本的に間引かれない
ファンが回り始めたということはFixedUpdateに相当重い処理を入れたんだろう
フレーム落ちしてもdeltaTimeで補完できる部分はUpdateに分割したほうがいいよ

966 :名前は開発中のものです。:2015/06/12(金) 14:37:36.40 ID:Qx6QZuPl.net
>>963
>transform.position = Vector3.Lerp(moviePoint.position, startPoint.position, Time.deltaTime * speed)
Lerpの使い方が悪い。第三引数で与える値は補間係数なので時間経過で0から1に変化させるようにする
ついで言うと第一引数が開始位置で第二の方が目的位置だから逆になってるよ

967 :名前は開発中のものです。:2015/06/12(金) 14:51:25.35 ID:hWrk7D/h.net
>>963
15秒かけたいならこうだろう。最初の方は多分関係ない。

public class Play : State{
publc Transform moviePoint;
publc Transform startPoint;
public float speed = 15.0f;
float timePass=0f;
public StateManager manager;
pubic Play(StateManager SM){
manager = SM;
}
void StateUpdate(){
timePass+=Time.deltaTime;
transform.position = Vector3.Lerp(moviePoint.position, startPoint.position, timePass/speed);
}

968 :名前は開発中のものです。:2015/06/12(金) 17:24:51.57 ID:yT7Nup/Q.net
>>965
キャラを追いかけるカメラはこんな感じの処理です。
もしかしてSlerpってすごい重いのですか?
キャラはまっすぐ進ませてるはずなのに横にガクガク動いて見えるんですよねぇ


public float distance = 5.0f;//被写体との距離
public float height = 3.0f;//被写体との高さ
void freeCamera(){
//start freeCamera
// Transform target = GameObject.FindWithTag("Player").transform;//被写体
// float distance = 5.0f;//被写体との距離
// float height = 3.0f;//被写体との高さ
// float heightDamping = 2.0f;//大きくするとカメラがはやくついてくる
// float rotationDamping = 3.0f;//大きくするとカメラがはやくついてくる
float smoothTime = 5f;
if (!target)return;//ターゲットがいないときはなにもしない
Vector3 basePosition = target.position;
basePosition -=target.forward*distance;
basePosition +=target.up*height;
// transform.position = Vector3.Slerp(transform.position,basePosition,smoothTime * Time.deltaTime);
transform.position = Vector3.Lerp(transform.position,basePosition,smoothTime*Time.deltaTime);
// transform.position = Vector3.Lerp(transform.position,basePosition,smoothTime*Time.deltaTime);
//Vector3 targetVelocity = target.GetComponent<Rigidbody> ().velocity;
//Vector3 targetVelocity = target.transform.forward;
Quaternion wantedRotation = Quaternion.LookRotation(target.position-transform.position);
// transform.rotation = Quaternion.Slerp(transform.rotation,wantedRotation,smoothTime*Time.deltaTime);
transform.rotation = Quaternion.Lerp(transform.rotation,wantedRotation,smoothTime*Time.deltaTime);
//end freeCamera
}

969 :名前は開発中のものです。:2015/06/12(金) 17:32:20.74 ID:hWrk7D/h.net
>>968
そういうカメラはLateUpdate()でやるべき、というのがUnityでの作法

970 :名前は開発中のものです。:2015/06/12(金) 18:01:24.03 ID:ESSmrvBP.net
>>968
> ,smoothTime*Time.deltaTime);
これの意図がイマイチ判らん
5.0f/Time.deltaTime になるわけだけどdeltaTimeは前フレームからの経過時間だから
補間の係数Tに使えるものじゃなくね
fixedupdateで安定したのは試してないけど定期的に呼ばれるからdeltaTimeのブレがなくて
変な数値で固定できていたからでは?

そもそもどういう挙動を意図してるかどうかわからんけど、それをアルゴリズム化できていないという
コーディング能力の問題じゃないですかねこれ

総レス数 1011
314 KB
新着レスの表示

掲示板に戻る 全部 前100 次100 最新50
read.cgi ver 2014.07.20.01.SC 2014/07/20 D ★