梶研 [三次元の歩行軌跡]
2023年5月16日

三次元の歩行軌跡
出席率
- 3年セミナー:??%
スケジュール
短期的な予定
- Unityでアニメーション
- 直角, 並行から歩行軌跡を綺麗に
進捗
Unityでアニメーション
c#スクリプトの注意点
ファイル名とクラス名を一致させなければならない
(2時間無駄にした...)
オブジェクトの移動(キーボード)
this.transform.position = new Vector3(x, y,z);
単純な移動はこれだけ
軌跡に沿ったオブジェクトの移動
使用したデータは 前回 のもの
1void Start() { 2 ... 3 while (!reader.EndOfStream) { 4 string[] line = reader.ReadLine().Split(','); 5 float x = float.Parse(line[1]); 6 float y = float.Parse(line[2]); 7 float z = float.Parse(line[3]); 8 positions.Add(new Vector3(x, z, y)); 9 } 10 ... 11} 12 13void Update() { 14 // アニメーションを実行する 15 timer += Time.deltaTime * 4; 16 if (timer >= 1f) { 17 Debug.Log(timer); 18 currentIndex++; 19 if (currentIndex >= positions.Count) currentIndex = 0; 20 21 transform.position = positions[currentIndex]; 22 timer = 0; 23 } 24}
GIFアニメみたい
=> 動作をなめらかにした
1歩進むごとの時間間隔が一定となっている
=> 測定時に合わせたい
実際の時間間隔に合わせたもの
実際の4倍速にしてある
次に移るまでの間隔を前の位置からの時間差に変更
1void Start() { 2 ... 3 while (!reader.EndOfStream) { 4 string[] line = reader.ReadLine().Split(','); 5 float x = float.Parse(line[1]); 6 float y = float.Parse(line[2]); 7 float z = float.Parse(line[3]); 8+ positions.Add(new Vector3(x, z, y)); 9+ times.Add(float.Parse(line[0])); 10 } 11 ... 12} 13 14void Update() { 15 // アニメーションを実行する 16 timer += Time.deltaTime * 4; 17 18+ float diff_time; 19+ if (currentIndex == 0) diff_time = 0; 20+ else diff_time = times[currentIndex] - times[currentIndex - 1]; 21 22+ if (timer >= diff_time) { 23 currentIndex++; 24 if (currentIndex >= positions.Count) currentIndex = 0; 25 26 transform.position = positions[currentIndex]; 27 timer = 0; 28 } 29}
滑らかにしたもの
自分で実装するのは大変だからアセット DG.Tweening を使用した
1+ using DG.Tweening; 2 3void Update() { 4 // アニメーションを実行する 5 timer += Time.deltaTime * 4; 6 7 float diff_time; 8 if (currentIndex == 0) diff_time = 0; 9 else diff_time = times[currentIndex] - times[currentIndex - 1]; 10 11 if (timer >= diff_time) { 12 currentIndex++; 13 if (currentIndex >= positions.Count) currentIndex = 0; 14 15- transform.position = positions[currentIndex]; 16+ this.transform.DOMove(positions[currentIndex], diff_time); 17 timer = 0; 18 } 19}
速度差がわかりづらい
=> 速さを変えたデータでもやるべきだった
余談
シス研の1年でweb制作&発表会をした
自分たちで技術力を上げていきたい!
自作のHUGOテンプレート
css 楽しい