回答編集履歴
1
formatting
test
CHANGED
@@ -2,73 +2,73 @@
|
|
2
2
|
|
3
3
|
ありがとうございました。
|
4
4
|
|
5
|
-
```
|
5
|
+
```C#
|
6
6
|
|
7
7
|
IEnumerator Start()
|
8
8
|
|
9
|
-
|
9
|
+
{
|
10
10
|
|
11
|
-
|
11
|
+
var p = t1.position;
|
12
12
|
|
13
|
-
|
13
|
+
while (true)
|
14
14
|
|
15
|
-
|
15
|
+
{
|
16
16
|
|
17
|
-
|
17
|
+
t1.position = p;
|
18
18
|
|
19
|
-
|
19
|
+
var direction = (t2.position - t1.position).normalized;
|
20
20
|
|
21
|
-
|
21
|
+
var distance = Vector2.Distance(t1.position, t2.position);
|
22
22
|
|
23
23
|
|
24
24
|
|
25
|
-
|
25
|
+
var v0 = initSpd;
|
26
26
|
|
27
|
-
|
27
|
+
var M = distance;
|
28
28
|
|
29
|
-
|
29
|
+
var T = duration;
|
30
30
|
|
31
|
-
|
31
|
+
var tm = M / v0;
|
32
32
|
|
33
|
-
|
33
|
+
var vm = v0 / T * tm;
|
34
34
|
|
35
|
-
|
35
|
+
var accel1 = (vm - v0) / (tm - 0);
|
36
36
|
|
37
|
-
|
37
|
+
var accel2 = (0 - vm) / (T - tm);
|
38
38
|
|
39
|
-
|
39
|
+
Debug.Log($"vo={v0}, M={M}, T={T}, tm={tm}, vm={vm}, accel1={accel1}, accel2={accel2}");
|
40
40
|
|
41
|
-
|
41
|
+
var v = initSpd;
|
42
42
|
|
43
|
-
|
43
|
+
var stime = Time.time;
|
44
44
|
|
45
|
-
|
45
|
+
var hist = 0f;
|
46
46
|
|
47
|
-
|
47
|
+
// update
|
48
48
|
|
49
|
-
|
49
|
+
yield return Utils.Coroutine.WhileForSeconds(T, () =>
|
50
50
|
|
51
|
-
|
51
|
+
{
|
52
52
|
|
53
|
-
|
53
|
+
t1.Translate(direction * v * Time.deltaTime);
|
54
54
|
|
55
|
-
|
55
|
+
hist += v * Time.deltaTime;
|
56
56
|
|
57
|
-
|
57
|
+
if (Time.time - stime <= tm)
|
58
58
|
|
59
|
-
|
59
|
+
v += accel1 * Time.deltaTime;
|
60
60
|
|
61
|
-
|
61
|
+
else
|
62
62
|
|
63
|
-
|
63
|
+
v += accel2 * Time.deltaTime;
|
64
64
|
|
65
|
-
|
65
|
+
});
|
66
66
|
|
67
|
-
|
67
|
+
Debug.Log($"経過時間={Time.time - stime}, 移動距離={hist}, v={v}");
|
68
68
|
|
69
|
-
|
69
|
+
}
|
70
70
|
|
71
|
-
|
71
|
+
}
|
72
72
|
|
73
73
|
|
74
74
|
|