2020년 1월 7일 화요일

간단한회전함수(UNITY)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
IEnumerator _smoothRotate(Transform obj, float value)
 
    {
 
        bool isRotateState = true;
 
        //float damping = 1;
 
        float damping = 100;
 
 
 
        while (isRotateState)
 
        {
 
 
 
            //+90하는 이유는 모르겠음 자식오브젝트라서그런듯????????????
 
            var desiredRotQ = Quaternion.Euler(obj.eulerAngles.x, value+90, obj.eulerAngles.z);
 
            obj.rotation = Quaternion.RotateTowards(obj.rotation, desiredRotQ, Time.deltaTime * damping);
 
 
 
            if (obj.eulerAngles.y == value + 90)
 
            {
 
                isRotateState = false;
 
            }
 
 
 
            yield return new WaitForEndOfFrame();
 
        }
 
    }
 
 
 
 
 
 
 
 
 
 
 
////////////////////////////
 
 
 
//이제는 컨트롤러가 그냥데이터 받아서 뿌려주는 역할만하는걸로 변경됨;
 
    IEnumerator _smoothRotate(Transform obj, float value)
 
    {
 
 
 
        //Debug.Log("value:" + value);
 
        bool isRotateState = true;
 
        //float damping = 1;
 
        float speed = 100//속도
 
       
 
        direction _direction=direction.none;
 
        Vector3 dir = Vector3.zero;
 
 
 
        if (value >= 0)
 
        {
 
 
 
            if (Prev_RoatationValue >= 0)
 
            {
 
                if (Prev_RoatationValue > value)
 
                {
 
                    dir = -Vector3.up;
 
                    _direction = direction.minus;
 
                }
 
                else
 
                {
 
                    dir = Vector3.up;
 
                    _direction = direction.plus;
 
                }
 
            }
 
            else
 
            {
 
                dir = Vector3.up;
 
                _direction = direction.plus;
 
            }
 
        }
 
        else
 
        {
 
            if (Prev_RoatationValue >= 0)
 
            {
 
                dir = -Vector3.up;
 
                _direction = direction.PlusToMinus;
 
            }
 
            else
 
            {
 
                //둘다음수일때도 대소비교로 방향정해야함
 
                if (Prev_RoatationValue > value)
 
                {
 
                    dir = -Vector3.up;
 
                    _direction = direction.minus;
 
                }
 
                else
 
                {
 
                    dir = Vector3.up;
 
                    _direction = direction.plus;
 
                }
 
 
 
               
 
            }
 
        }
 
 
 
 
 
       
 
 
 
       
 
 
 
        yield return new WaitForEndOfFrame();
 
 
 
 
 
        while (isRotateState)
 
        {
 
            //var desiredRotQ = Quaternion.Euler(obj.eulerAngles.x, value, obj.eulerAngles.z);
 
            //obj.rotation = Quaternion.RotateTowards(obj.rotation, desiredRotQ, Time.deltaTime * damping);
 
            //if (obj.eulerAngles.y == value)
 
            //{
 
            //    isRotateState = false;
 
            //}
 
 
 
 
 
            obj.Rotate(dir * Time.deltaTime* speed, Space.Self);
 
 
 
 
 
            switch (_direction)
 
            {
 
                case direction.plus:
 
 
 
                    Debug.Log("plus");
 
 
 
                    if (value < 0)
 
                    {
 
                        if (obj.eulerAngles.y - 360f > value)
 
                        {
 
                            isRotateState = false;
 
                        }
 
                    }
 
                    else
 
                    {
 
                        if (0 < obj.eulerAngles.y && obj.eulerAngles.y < 170)
 
                        {
 
                            if (obj.eulerAngles.y > value)
 
                            {
 
                                isRotateState = false;
 
                            }
 
                        }
 
                    }
 
 
 
 
 
                    break;
 
 
 
                case direction.minus:
 
 
 
 
 
                    Debug.Log("minus");
 
 
 
                    if (value < 0)
 
                    {
 
 
 
                        if (obj.eulerAngles.y - 360f < value)
 
                        {
 
                            isRotateState = false;
 
                        }
 
                    }
 
                    else
 
                    {
 
                     
 
                        if (obj.eulerAngles.y < value)
 
                        {
 
                            isRotateState = false;
 
                        }
 
                    }
 
 
 
                   
 
                    break;
 
 
 
                case direction.PlusToMinus:
 
                    //Debug.Log("PlusToMinus");
 
                    if ((obj.eulerAngles.y - 360f) > -170)
 
                    {
 
                        //Debug.Log("1111 value:" + value + ",eulerAngles.y" + (obj.eulerAngles.y - 360f));
 
 
 
                        if (obj.eulerAngles.y - 360f < value)
 
                        {
 
                            isRotateState = false;
 
                        }
 
                    }
 
                   
 
                    break;
 
 
 
            }
 
 
 
            yield return new WaitForEndOfFrame();
 
        }
 
    }




IEnumerator rotate_90()
    {
        Debug.Log("Start!!!");

        rot = Quaternion.Euler(transform.eulerAngles + new Vector3(0,0,90));
      
        for (var t = 0f; t < 1; t += Time.deltaTime / 1)
        {
            transform.rotation = Quaternion.Slerp(transform.rotation, rot, t);
            yield return null;
        }
    }


















cs

댓글 없음:

댓글 쓰기

git rejected error(feat. cherry-pick)

 문제 아무 생각 없이 pull을 받지않고 로컬에서 작업! 커밋, 푸시 진행을 해버렷다. push에선 remote와 다르니 당연히 pull을 진행해라고 하지만 로컬에서 작업한 내용을 백업하지 않고 진행하기에는 부담스럽다(로컬작업 유실 가능성) 해결하려...