質問編集履歴

13

追記⑥

2018/06/22 11:15

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -353,3 +353,47 @@
353
353
  ※移動時はy方向に動きません。
354
354
 
355
355
  ![イメージ説明](3c429dd9b0c2666eb0dc12233c30da3b.png)
356
+
357
+
358
+
359
+ ### 追記⑥
360
+
361
+
362
+
363
+ 追記⑤の画像の停止位置とほぼ変わらない状態でした。
364
+
365
+ ```C#
366
+
367
+ void FixedUpdate(){
368
+
369
+
370
+
371
+ Vector3 viewport = Camera.main.WorldToViewportPoint(this.transform.position);
372
+
373
+ Vector3 viewmin = new Vector3(0.0f, 0.0f,viewport.z);
374
+
375
+ Vector3 viewmax = new Vector3(1.0f, 1.0f,viewport.z);
376
+
377
+ min = Camera.main.ViewportToWorldPoint(viewmin);
378
+
379
+ max = Camera.main.ViewportToWorldPoint(viewmax);
380
+
381
+
382
+
383
+ Vector3 baseVelocity = this.transform.right * speed;
384
+
385
+ Vector3 pos = this.transform.position + this.transform.TransformDirection(baseVelocity);
386
+
387
+ pos.x = Mathf.Clamp(pos.x, min.x, max.x);
388
+
389
+
390
+
391
+ Vector3 vel = transform.InverseTransformDirection(pos - this.transform.position);
392
+
393
+ vel.z = vel.z * vel.x /baseVelocity.x;
394
+
395
+ rb.velocity = vel;
396
+
397
+ }
398
+
399
+ ```

12

修正5-4

2018/06/22 11:15

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -348,7 +348,7 @@
348
348
 
349
349
 
350
350
 
351
- の位置で停止しました。ちょっと画面外に出てしまっています。
351
+ 画像の位置で停止しました。ちょっと画面外に出てしまっています。
352
352
 
353
353
  ※移動時はy方向に動きません。
354
354
 

11

修正5-3

2018/06/21 15:20

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -348,7 +348,7 @@
348
348
 
349
349
 
350
350
 
351
- 次の位置で停止しました。ちょっと画面外に出過ぎてしまっています。
351
+ 次の位置で停止しました。ちょっと画面外に出てしまっています。
352
352
 
353
353
  ※移動時はy方向に動きません。
354
354
 

10

修正5-2

2018/06/21 15:19

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -348,6 +348,8 @@
348
348
 
349
349
 
350
350
 
351
+ 次の位置で停止しました。ちょっと画面外に出過ぎてしまっています。
352
+
351
- 次の位置で停止しました。※移動時はy方向に動きません。
353
+ ※移動時はy方向に動きません。
352
354
 
353
355
  ![イメージ説明](3c429dd9b0c2666eb0dc12233c30da3b.png)

9

追記⑤

2018/06/21 15:18

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -299,3 +299,55 @@
299
299
  rb.velocity = transform.InverseTransformDirection(pos - this.transform.position);
300
300
 
301
301
  ```
302
+
303
+ ### 追記⑤
304
+
305
+
306
+
307
+ ```C#
308
+
309
+ void Update () {
310
+
311
+ Vector3 viewport = Camera.main.WorldToViewportPoint(this.transform.position);
312
+
313
+ Vector3 viewmin = new Vector3(0.0f, 0.0f,viewport.z);
314
+
315
+ Vector3 viewmax = new Vector3(1.0f, 1.0f,viewport.z);
316
+
317
+ min = Camera.main.ViewportToWorldPoint(viewmin);
318
+
319
+ max = Camera.main.ViewportToWorldPoint(viewmax);
320
+
321
+ }
322
+
323
+
324
+
325
+
326
+
327
+ void FixedUpdate(){
328
+
329
+
330
+
331
+ Vector3 baseVelocity = this.transform.right * speed;
332
+
333
+ Vector3 pos = this.transform.position + this.transform.TransformDirection(baseVelocity);
334
+
335
+ pos.x = Mathf.Clamp(pos.x, min.x, max.x);
336
+
337
+
338
+
339
+ Vector3 vel = transform.InverseTransformDirection(pos - this.transform.position);
340
+
341
+ vel.z = vel.z * vel.x /baseVelocity.x;
342
+
343
+ rb.velocity = vel;
344
+
345
+ }
346
+
347
+ ```
348
+
349
+
350
+
351
+ 次の位置で停止しました。※移動時はy方向に動きません。
352
+
353
+ ![イメージ説明](3c429dd9b0c2666eb0dc12233c30da3b.png)

8

図を修正

2018/06/21 14:39

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -246,7 +246,7 @@
246
246
 
247
247
 
248
248
 
249
- ![イメージ説明](9c167760f0b31aa99180c46e21fc72c0.jpeg)
249
+ ![イメージ説明](56560b3e04baac946c47d14b7f732d1c.png)
250
250
 
251
251
 
252
252
 

7

追記④

2018/06/21 00:56

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -247,3 +247,55 @@
247
247
 
248
248
 
249
249
  ![イメージ説明](9c167760f0b31aa99180c46e21fc72c0.jpeg)
250
+
251
+
252
+
253
+ ```C#
254
+
255
+ Vector3 min;
256
+
257
+ Vector3 max;
258
+
259
+
260
+
261
+ void Start () {
262
+
263
+ }
264
+
265
+
266
+
267
+
268
+
269
+ void Update () {
270
+
271
+ Vector3 viewport = Camera.main.WorldToViewportPoint(this.transform.position);
272
+
273
+ Vector3 viewmin = new Vector3(0.0f, 0.0f,viewport.z);
274
+
275
+ Vector3 viewmax = new Vector3(1.0f, 1.0f,viewport.z);
276
+
277
+ min = Camera.main.ViewportToWorldPoint(viewmin);
278
+
279
+ max = Camera.main.ViewportToWorldPoint(viewmax);
280
+
281
+ }
282
+
283
+
284
+
285
+
286
+
287
+ void FixedUpdate(){
288
+
289
+
290
+
291
+ Vector3 pos = this.transform.position + this.transform.TransformDirection(this.transform.right * speed);
292
+
293
+ pos.x = Mathf.Clamp(pos.x, min.x, max.x);
294
+
295
+ pos.z = Mathf.Clamp(pos.z, min.z, max.z);
296
+
297
+
298
+
299
+ rb.velocity = transform.InverseTransformDirection(pos - this.transform.position);
300
+
301
+ ```

6

追記④

2018/06/20 15:19

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -242,8 +242,8 @@
242
242
 
243
243
 
244
244
 
245
- ### メモ
245
+ ### 追記④
246
-
247
-
248
-
246
+
247
+
248
+
249
- ![イメージ説明](50bfeea4ed6859aaa45c83990ed6ff72.jpeg)
249
+ ![イメージ説明](9c167760f0b31aa99180c46e21fc72c0.jpeg)

5

仕様メモ

2018/06/20 14:41

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -239,3 +239,11 @@
239
239
 
240
240
 
241
241
  ![イメージ説明](cec7f6b43a573bb70320ca4eed4aa506.jpeg)
242
+
243
+
244
+
245
+ ### メモ
246
+
247
+
248
+
249
+ ![イメージ説明](50bfeea4ed6859aaa45c83990ed6ff72.jpeg)

4

追記③

2018/06/20 13:22

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -193,3 +193,49 @@
193
193
  }
194
194
 
195
195
  ```
196
+
197
+
198
+
199
+ ### 追記③
200
+
201
+
202
+
203
+ ```C#
204
+
205
+ Vector3 max;
206
+
207
+
208
+
209
+ void Start () {
210
+
211
+ //空のゲームオブジェクトの位置に設定。
212
+
213
+ max = go.transform.position;
214
+
215
+ }
216
+
217
+
218
+
219
+ void FixedUpdate(){
220
+
221
+
222
+
223
+ Vector3 pos = this.transform.position + this.transform.TransformDirection(this.transform.right * speed);
224
+
225
+ pos.x = Mathf.Clamp(pos.x, min.x, max.x);
226
+
227
+
228
+
229
+ rb.velocity = transform.InverseTransformDirection(pos - this.transform.position);
230
+
231
+ }
232
+
233
+ ```
234
+
235
+
236
+
237
+ ![イメージ説明](d58d07aa0f72938f5010dfed1c12c687.jpeg)
238
+
239
+
240
+
241
+ ![イメージ説明](cec7f6b43a573bb70320ca4eed4aa506.jpeg)

3

追記②

2018/06/19 11:31

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -126,6 +126,8 @@
126
126
 
127
127
  max = Camera.main.ViewportToWorldPoint(viewmax);
128
128
 
129
+
130
+
129
131
  }
130
132
 
131
133
 
@@ -170,6 +172,8 @@
170
172
 
171
173
  max = Camera.main.ViewportToWorldPoint(viewmax);
172
174
 
175
+ Debug.Log(max);
176
+
173
177
  }
174
178
 
175
179
 

2

追記②

2018/06/18 15:21

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -143,3 +143,49 @@
143
143
  rb.velocity = pos - this.transform.position;
144
144
 
145
145
  ```
146
+
147
+
148
+
149
+ ### 追記②
150
+
151
+ ```
152
+
153
+ float speed = 2.0f;
154
+
155
+ Vector3 min;
156
+
157
+ Vector3 max;
158
+
159
+
160
+
161
+ void Update () {
162
+
163
+ Vector3 viewport = Camera.main.WorldToViewportPoint(this.transform.position);
164
+
165
+ Vector3 viewmin = new Vector3(0.0f, 0.0f,viewport.z);
166
+
167
+ Vector3 viewmax = new Vector3(1.0f, 1.0f,viewport.z);
168
+
169
+ min = Camera.main.ViewportToWorldPoint(viewmin);
170
+
171
+ max = Camera.main.ViewportToWorldPoint(viewmax);
172
+
173
+ }
174
+
175
+
176
+
177
+ void FixedUpdate(){
178
+
179
+
180
+
181
+ Vector3 pos = this.transform.position + this.transform.TransformDirection(this.transform.right * speed);
182
+
183
+ pos.x = Mathf.Clamp(pos.x, min.x, max.x);
184
+
185
+
186
+
187
+ rb.velocity = transform.InverseTransformDirection(pos - this.transform.position);
188
+
189
+ }
190
+
191
+ ```

1

画面外

2018/06/18 15:18

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -105,3 +105,41 @@
105
105
  }
106
106
 
107
107
  ```
108
+
109
+
110
+
111
+ ### 追記。
112
+
113
+
114
+
115
+ ```C#
116
+
117
+ void Update () {
118
+
119
+ Vector3 viewport = Camera.main.WorldToViewportPoint(this.transform.position);
120
+
121
+ Vector3 viewmin = new Vector3(0.0f, 0.0f,viewport.z);
122
+
123
+ Vector3 viewmax = new Vector3(1.0f, 1.0f,viewport.z);
124
+
125
+ min = Camera.main.ViewportToWorldPoint(viewmin);
126
+
127
+ max = Camera.main.ViewportToWorldPoint(viewmax);
128
+
129
+ }
130
+
131
+
132
+
133
+ void FixedUpdate(){
134
+
135
+
136
+
137
+ Vector3 pos = this.transform.position + (this.transform.right * speed);
138
+
139
+ pos.x = Mathf.Clamp(pos.x, min.x, max.x);
140
+
141
+
142
+
143
+ rb.velocity = pos - this.transform.position;
144
+
145
+ ```