SatooRu's Profile

全ての記事梶研の進捗日常の記録制作物一覧

梶研 [三次元の歩行軌跡]

2023年5月16日

thumbnail

三次元の歩行軌跡

出席率

  • 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制作&発表会をした

9FBCD0B8-8C38-42BF-A121-3F1A11E1588F_Original.jpg (2.0 MB)

自分たちで技術力を上げていきたい!

自作のHUGOテンプレート

スクリーンショット 2023-05-16 9.23.55.png (303.2 kB) スクリーンショット 2023-05-16 9.24.06.png (232.3 kB)

css 楽しい