質問編集履歴
2
追記①と追記②を追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -72,4 +72,68 @@
|
|
72
72
|
{
|
73
73
|
transform.rotation = startRotation * Quaternion.Euler(0f, 0f, Mathf.Sin((Time.time - startTime) * speed * Time.deltaTime) * maxAngle);
|
74
74
|
}
|
75
|
+
```
|
76
|
+
|
77
|
+
### 追記①
|
78
|
+
・時間を指定しないイージング。
|
79
|
+
```C#
|
80
|
+
float speed = 0.5f;
|
81
|
+
IEnumerator MoveCoroutine(Transform move, Transform startPoint, Transform endPoint){
|
82
|
+
move.position = startPoint.position;
|
83
|
+
while(move.position != endPoint.position){
|
84
|
+
move.position = Vector3.Lerp(move.position, endPoint.position, Time.deltaTime * speed);
|
85
|
+
float distance = (endPoint.position - move.transform.position).sqrMagnitude;
|
86
|
+
if(distance < 0.0001){
|
87
|
+
move.position = endPoint.position;
|
88
|
+
}
|
89
|
+
yield return null;
|
90
|
+
}
|
91
|
+
Debug.Log("finish");
|
92
|
+
}
|
93
|
+
```
|
94
|
+
|
95
|
+
### 追記②
|
96
|
+
・easeOutElasticの元のコード。
|
97
|
+
```
|
98
|
+
function easeOutElastic(x: number): number {
|
99
|
+
const c4 = (2 * Math.PI) / 3;
|
100
|
+
|
101
|
+
return x === 0
|
102
|
+
? 0
|
103
|
+
: x === 1
|
104
|
+
? 1
|
105
|
+
: pow(2, -10 * x) * sin((x * 10 - 0.75) * c4) + 1;
|
106
|
+
}
|
107
|
+
```
|
108
|
+
|
109
|
+
・試したコード(EaseOutElastic)
|
110
|
+
```C#
|
111
|
+
static float EaseOutElastic(float t)
|
112
|
+
{
|
113
|
+
const float c4 = (2.0f * Mathf.PI) / 3.0f;
|
114
|
+
|
115
|
+
t = Mathf.Clamp01(t);
|
116
|
+
return t == 0 ? 0 : t == 1 ? 1 : Mathf.Pow(2, -10 * t) * Mathf.Sin((t * 10 - 0.75f) * c4) + 1;
|
117
|
+
}
|
118
|
+
|
119
|
+
float animationLength = 5.0f;
|
120
|
+
IEnumerator MoveCoroutine(Transform move, Transform startPoint, Transform endPoint){
|
121
|
+
move.position = startPoint.position;
|
122
|
+
for (float time = 0.0f; time < animationLength; time += Time.deltaTime){
|
123
|
+
move.position = Vector3.Lerp(startPoint.position, endPoint.position, EaseOutElastic(time / this.animationLength));
|
124
|
+
yield return null;
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
static float EaseOutExpo(float t)
|
129
|
+
{
|
130
|
+
t = Mathf.Clamp01(t);
|
131
|
+
return t < 1.0f ? 1.0f - Mathf.Pow(2.0f, -10.0f * t) : 1.0f;
|
132
|
+
}
|
133
|
+
|
134
|
+
static float EaseOutCubic(float t)
|
135
|
+
{
|
136
|
+
var it = 1.0f - Mathf.Clamp01(t);
|
137
|
+
return 1.0f - (it * it * it);
|
138
|
+
}
|
75
139
|
```
|
1
改行
title
CHANGED
File without changes
|
body
CHANGED
@@ -39,8 +39,8 @@
|
|
39
39
|
```
|
40
40
|
|
41
41
|
・質問2。
|
42
|
-
Lerpのイージング処理では、質問1と違って、Time.deltaTimeを掛けることが必要と思い、
|
42
|
+
Lerpのイージング処理では、質問1と違って、Time.deltaTimeを掛けることが必要と思い、
|
43
|
-
一瞬で、startPointからendPointに移動してしまいます。
|
43
|
+
下記コードを組んでみたのですが、一瞬で、startPointからendPointに移動してしまいます。
|
44
44
|
for文の中で2つのログを取ってみたのですが、問題なさそうでした。
|
45
45
|
下記コードはどのように修正すればイージング処理になりますか?
|
46
46
|
```C#
|