質問編集履歴

1

現状の修正を行いました。

2019/07/16 13:35

投稿

zenobread
zenobread

スコア44

test CHANGED
File without changes
test CHANGED
@@ -137,3 +137,141 @@
137
137
 
138
138
 
139
139
  どうかよろしくお願いいたします。
140
+
141
+
142
+
143
+ 編集
144
+
145
+ 惑星の上をキャラクターが歩くことまではできました。
146
+
147
+ ただ右左の矢印キーを押すとカメラが一瞬おかしくなってしまうことが悩みです。
148
+
149
+ ```C#
150
+
151
+ using System.Collections;
152
+
153
+ using System.Collections.Generic;
154
+
155
+ using UnityEngine;
156
+
157
+
158
+
159
+ public class BearAnimConScp : MonoBehaviour
160
+
161
+ {
162
+
163
+ private static float G= 6.67259f;
164
+
165
+ Rigidbody br_body, sp_body;
166
+
167
+ public GameObject Sphere;
168
+
169
+ Vector3 dir, heading,go_dir;
170
+
171
+ float speed = 15.0f;
172
+
173
+ float angleDir,x_dir;
174
+
175
+ private Vector3 move;
176
+
177
+ private Vector3 mir_move;
178
+
179
+ // Start is called before the first frame update
180
+
181
+ void Start()
182
+
183
+ {
184
+
185
+ sp_body = GetComponent<Rigidbody>();
186
+
187
+ br_body= GetComponent<Rigidbody>();
188
+
189
+ move = new Vector3(0,0,0);
190
+
191
+ mir_move = -move;
192
+
193
+ }
194
+
195
+
196
+
197
+ // Update is called once per frame
198
+
199
+ void Update()
200
+
201
+ {
202
+
203
+ if (Input.GetKey("up"))
204
+
205
+ {
206
+
207
+ transform.position += transform.forward * speed * Time.deltaTime;
208
+
209
+ move+= transform.forward * speed * Time.deltaTime;
210
+
211
+ transform.rotation = Quaternion.LookRotation(-dir, -move) * Quaternion.FromToRotation(Vector3.up, Vector3.forward);
212
+
213
+ }
214
+
215
+ if (Input.GetKey("down"))
216
+
217
+ {
218
+
219
+ transform.position -= transform.forward * speed * Time.deltaTime;
220
+
221
+ move-= transform.forward * speed * Time.deltaTime;
222
+
223
+ transform.rotation = Quaternion.LookRotation(-dir, -this.transform.forward) * Quaternion.FromToRotation(Vector3.up, Vector3.forward);
224
+
225
+ }
226
+
227
+ if (Input.GetKey("right"))
228
+
229
+ {
230
+
231
+ transform.position += transform.right * speed * Time.deltaTime;
232
+
233
+ move+= transform.right * speed * Time.deltaTime;
234
+
235
+ transform.rotation = Quaternion.LookRotation(this.transformm.forward, -dir) * Quaternion.FromToRotation(Vector3.up, Vector3.right);
236
+
237
+ }
238
+
239
+ if (Input.GetKey("left"))
240
+
241
+ {
242
+
243
+ transform.position -= transform.right * speed * Time.deltaTime;
244
+
245
+ move-= transform.right * speed * Time.deltaTime;
246
+
247
+ transform.rotation = Quaternion.LookRotation(this.transform.forward,-dir) * Quaternion.FromToRotation(Vector3.up, Vector3.left);
248
+
249
+ }
250
+
251
+
252
+
253
+ if (!Input.anyKeyDown)
254
+
255
+ {
256
+
257
+ move = new Vector3(0, 0, 0);
258
+
259
+ transform.rotation = Quaternion.LookRotation(-dir, -this.transform.forward) * Quaternion.FromToRotation(Vector3.up, Vector3.forward);
260
+
261
+ }
262
+
263
+
264
+
265
+ heading = (Sphere.transform.position - this.transform.position) / 1;
266
+
267
+ dir = G * heading.normalized * (sp_body.mass * br_body.mass) / (heading.sqrMagnitude);
268
+
269
+ br_body.AddForce(dir*20);
270
+
271
+ }
272
+
273
+ }
274
+
275
+
276
+
277
+ ```