teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

13

追記⑥

2018/06/22 11:15

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -175,4 +175,26 @@
175
175
 
176
176
  下の画像の位置で停止しました。ちょっと画面外に出てしまっています。
177
177
  ※移動時はy方向に動きません。
178
- ![イメージ説明](3c429dd9b0c2666eb0dc12233c30da3b.png)
178
+ ![イメージ説明](3c429dd9b0c2666eb0dc12233c30da3b.png)
179
+
180
+ ### 追記⑥
181
+
182
+ 追記⑤の画像の停止位置とほぼ変わらない状態でした。
183
+ ```C#
184
+ void FixedUpdate(){
185
+
186
+ Vector3 viewport = Camera.main.WorldToViewportPoint(this.transform.position);
187
+ Vector3 viewmin = new Vector3(0.0f, 0.0f,viewport.z);
188
+ Vector3 viewmax = new Vector3(1.0f, 1.0f,viewport.z);
189
+ min = Camera.main.ViewportToWorldPoint(viewmin);
190
+ max = Camera.main.ViewportToWorldPoint(viewmax);
191
+
192
+ Vector3 baseVelocity = this.transform.right * speed;
193
+ Vector3 pos = this.transform.position + this.transform.TransformDirection(baseVelocity);
194
+ pos.x = Mathf.Clamp(pos.x, min.x, max.x);
195
+
196
+ Vector3 vel = transform.InverseTransformDirection(pos - this.transform.position);
197
+ vel.z = vel.z * vel.x /baseVelocity.x;
198
+ rb.velocity = vel;
199
+ }
200
+ ```

12

修正5-4

2018/06/22 11:15

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -173,6 +173,6 @@
173
173
  }
174
174
  ```
175
175
 
176
- の位置で停止しました。ちょっと画面外に出てしまっています。
176
+ 画像の位置で停止しました。ちょっと画面外に出てしまっています。
177
177
  ※移動時はy方向に動きません。
178
178
  ![イメージ説明](3c429dd9b0c2666eb0dc12233c30da3b.png)

11

修正5-3

2018/06/21 15:20

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -173,6 +173,6 @@
173
173
  }
174
174
  ```
175
175
 
176
- 次の位置で停止しました。ちょっと画面外に出過ぎてしまっています。
176
+ 次の位置で停止しました。ちょっと画面外に出てしまっています。
177
177
  ※移動時はy方向に動きません。
178
178
  ![イメージ説明](3c429dd9b0c2666eb0dc12233c30da3b.png)

10

修正5-2

2018/06/21 15:19

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -173,5 +173,6 @@
173
173
  }
174
174
  ```
175
175
 
176
+ 次の位置で停止しました。ちょっと画面外に出過ぎてしまっています。
176
- 次の位置で停止しました。※移動時はy方向に動きません。
177
+ ※移動時はy方向に動きません。
177
178
  ![イメージ説明](3c429dd9b0c2666eb0dc12233c30da3b.png)

9

追記⑤

2018/06/21 15:18

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -148,4 +148,30 @@
148
148
  pos.z = Mathf.Clamp(pos.z, min.z, max.z);
149
149
 
150
150
  rb.velocity = transform.InverseTransformDirection(pos - this.transform.position);
151
- ```
151
+ ```
152
+ ### 追記⑤
153
+
154
+ ```C#
155
+ void Update () {
156
+ Vector3 viewport = Camera.main.WorldToViewportPoint(this.transform.position);
157
+ Vector3 viewmin = new Vector3(0.0f, 0.0f,viewport.z);
158
+ Vector3 viewmax = new Vector3(1.0f, 1.0f,viewport.z);
159
+ min = Camera.main.ViewportToWorldPoint(viewmin);
160
+ max = Camera.main.ViewportToWorldPoint(viewmax);
161
+ }
162
+
163
+
164
+ void FixedUpdate(){
165
+
166
+ Vector3 baseVelocity = this.transform.right * speed;
167
+ Vector3 pos = this.transform.position + this.transform.TransformDirection(baseVelocity);
168
+ pos.x = Mathf.Clamp(pos.x, min.x, max.x);
169
+
170
+ Vector3 vel = transform.InverseTransformDirection(pos - this.transform.position);
171
+ vel.z = vel.z * vel.x /baseVelocity.x;
172
+ rb.velocity = vel;
173
+ }
174
+ ```
175
+
176
+ 次の位置で停止しました。※移動時はy方向に動きません。
177
+ ![イメージ説明](3c429dd9b0c2666eb0dc12233c30da3b.png)

8

図を修正

2018/06/21 14:39

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -122,7 +122,7 @@
122
122
 
123
123
  ### 追記④
124
124
 
125
- ![イメージ説明](9c167760f0b31aa99180c46e21fc72c0.jpeg)
125
+ ![イメージ説明](56560b3e04baac946c47d14b7f732d1c.png)
126
126
 
127
127
  ```C#
128
128
  Vector3 min;

7

追記④

2018/06/21 00:56

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -122,4 +122,30 @@
122
122
 
123
123
  ### 追記④
124
124
 
125
- ![イメージ説明](9c167760f0b31aa99180c46e21fc72c0.jpeg)
125
+ ![イメージ説明](9c167760f0b31aa99180c46e21fc72c0.jpeg)
126
+
127
+ ```C#
128
+ Vector3 min;
129
+ Vector3 max;
130
+
131
+ void Start () {
132
+ }
133
+
134
+
135
+ void Update () {
136
+ Vector3 viewport = Camera.main.WorldToViewportPoint(this.transform.position);
137
+ Vector3 viewmin = new Vector3(0.0f, 0.0f,viewport.z);
138
+ Vector3 viewmax = new Vector3(1.0f, 1.0f,viewport.z);
139
+ min = Camera.main.ViewportToWorldPoint(viewmin);
140
+ max = Camera.main.ViewportToWorldPoint(viewmax);
141
+ }
142
+
143
+
144
+ void FixedUpdate(){
145
+
146
+ Vector3 pos = this.transform.position + this.transform.TransformDirection(this.transform.right * speed);
147
+ pos.x = Mathf.Clamp(pos.x, min.x, max.x);
148
+ pos.z = Mathf.Clamp(pos.z, min.z, max.z);
149
+
150
+ rb.velocity = transform.InverseTransformDirection(pos - this.transform.position);
151
+ ```

6

追記④

2018/06/20 15:19

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -120,6 +120,6 @@
120
120
 
121
121
  ![イメージ説明](cec7f6b43a573bb70320ca4eed4aa506.jpeg)
122
122
 
123
- ### メモ
123
+ ### 追記④
124
124
 
125
- ![イメージ説明](50bfeea4ed6859aaa45c83990ed6ff72.jpeg)
125
+ ![イメージ説明](9c167760f0b31aa99180c46e21fc72c0.jpeg)

5

仕様メモ

2018/06/20 14:41

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -118,4 +118,8 @@
118
118
 
119
119
  ![イメージ説明](d58d07aa0f72938f5010dfed1c12c687.jpeg)
120
120
 
121
- ![イメージ説明](cec7f6b43a573bb70320ca4eed4aa506.jpeg)
121
+ ![イメージ説明](cec7f6b43a573bb70320ca4eed4aa506.jpeg)
122
+
123
+ ### メモ
124
+
125
+ ![イメージ説明](50bfeea4ed6859aaa45c83990ed6ff72.jpeg)

4

追記③

2018/06/20 13:22

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -95,4 +95,27 @@
95
95
 
96
96
  rb.velocity = transform.InverseTransformDirection(pos - this.transform.position);
97
97
  }
98
- ```
98
+ ```
99
+
100
+ ### 追記③
101
+
102
+ ```C#
103
+ Vector3 max;
104
+
105
+ void Start () {
106
+ //空のゲームオブジェクトの位置に設定。
107
+ max = go.transform.position;
108
+ }
109
+
110
+ void FixedUpdate(){
111
+
112
+ Vector3 pos = this.transform.position + this.transform.TransformDirection(this.transform.right * speed);
113
+ pos.x = Mathf.Clamp(pos.x, min.x, max.x);
114
+
115
+ rb.velocity = transform.InverseTransformDirection(pos - this.transform.position);
116
+ }
117
+ ```
118
+
119
+ ![イメージ説明](d58d07aa0f72938f5010dfed1c12c687.jpeg)
120
+
121
+ ![イメージ説明](cec7f6b43a573bb70320ca4eed4aa506.jpeg)

3

追記②

2018/06/19 11:31

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -62,6 +62,7 @@
62
62
  Vector3 viewmax = new Vector3(1.0f, 1.0f,viewport.z);
63
63
  min = Camera.main.ViewportToWorldPoint(viewmin);
64
64
  max = Camera.main.ViewportToWorldPoint(viewmax);
65
+
65
66
  }
66
67
 
67
68
  void FixedUpdate(){
@@ -84,6 +85,7 @@
84
85
  Vector3 viewmax = new Vector3(1.0f, 1.0f,viewport.z);
85
86
  min = Camera.main.ViewportToWorldPoint(viewmin);
86
87
  max = Camera.main.ViewportToWorldPoint(viewmax);
88
+ Debug.Log(max);
87
89
  }
88
90
 
89
91
  void FixedUpdate(){

2

追記②

2018/06/18 15:21

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -70,4 +70,27 @@
70
70
  pos.x = Mathf.Clamp(pos.x, min.x, max.x);
71
71
 
72
72
  rb.velocity = pos - this.transform.position;
73
+ ```
74
+
75
+ ### 追記②
76
+ ```
77
+ float speed = 2.0f;
78
+ Vector3 min;
79
+ Vector3 max;
80
+
81
+ void Update () {
82
+ Vector3 viewport = Camera.main.WorldToViewportPoint(this.transform.position);
83
+ Vector3 viewmin = new Vector3(0.0f, 0.0f,viewport.z);
84
+ Vector3 viewmax = new Vector3(1.0f, 1.0f,viewport.z);
85
+ min = Camera.main.ViewportToWorldPoint(viewmin);
86
+ max = Camera.main.ViewportToWorldPoint(viewmax);
87
+ }
88
+
89
+ void FixedUpdate(){
90
+
91
+ Vector3 pos = this.transform.position + this.transform.TransformDirection(this.transform.right * speed);
92
+ pos.x = Mathf.Clamp(pos.x, min.x, max.x);
93
+
94
+ rb.velocity = transform.InverseTransformDirection(pos - this.transform.position);
95
+ }
73
96
  ```

1

画面外

2018/06/18 15:18

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -51,4 +51,23 @@
51
51
  this.transform.position = limit;
52
52
  }
53
53
  }
54
+ ```
55
+
56
+ ### 追記。
57
+
58
+ ```C#
59
+ void Update () {
60
+ Vector3 viewport = Camera.main.WorldToViewportPoint(this.transform.position);
61
+ Vector3 viewmin = new Vector3(0.0f, 0.0f,viewport.z);
62
+ Vector3 viewmax = new Vector3(1.0f, 1.0f,viewport.z);
63
+ min = Camera.main.ViewportToWorldPoint(viewmin);
64
+ max = Camera.main.ViewportToWorldPoint(viewmax);
65
+ }
66
+
67
+ void FixedUpdate(){
68
+
69
+ Vector3 pos = this.transform.position + (this.transform.right * speed);
70
+ pos.x = Mathf.Clamp(pos.x, min.x, max.x);
71
+
72
+ rb.velocity = pos - this.transform.position;
54
73
  ```