質問編集履歴

1

追記

2019/07/21 14:29

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -137,3 +137,71 @@
137
137
  rigidbody.AddTorque(rotationTorque + restoringTorque);
138
138
 
139
139
  ```
140
+
141
+
142
+
143
+ ### 追記
144
+
145
+
146
+
147
+ ```C#
148
+
149
+ void FixedUpdate()
150
+
151
+ {
152
+
153
+ float x = Input.GetAxis("Horizontal");
154
+
155
+ float y = Input.GetAxis("Vertical");
156
+
157
+
158
+
159
+ // xとyにspeedを掛ける
160
+
161
+ rigidbody.AddForce(x * speed, y * speed, 0);
162
+
163
+
164
+
165
+ Vector3 moveVector = Vector3.zero;
166
+
167
+
168
+
169
+ //rigidbody.AddForce(moveForceMultiplier * (moveVector - rigidbody.velocity));
170
+
171
+
172
+
173
+ // プレイヤーの入力に応じて姿勢をひねろうとするトルク
174
+
175
+ Vector3 rotationTorque = new Vector3(-y * pitchTorqueMagnitude, x * yawTorqueMagnitude, -x * rollTorqueMagnitude);
176
+
177
+
178
+
179
+ Quaternion target_rot = this.transform.rotation;
180
+
181
+ Quaternion rot = target_rot * Quaternion.Inverse(this.transform.rotation);
182
+
183
+ if(rot.w < 0f){
184
+
185
+ rot.x = -rot.x;
186
+
187
+ rot.y = -rot.y;
188
+
189
+ rot.z = -rot.z;
190
+
191
+ rot.w = -rot.w;
192
+
193
+ }
194
+
195
+ Vector3 restoringTorque = new Vector3(rot.x, rot.y, rot.z) * 100f;
196
+
197
+ // 機体にトルクを加える
198
+
199
+ // rigidbody.AddTorque(rotationTorque);
200
+
201
+ rigidbody.AddTorque(rotationTorque + restoringTorque);
202
+
203
+
204
+
205
+ }
206
+
207
+ ```