質問編集履歴
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -67,4 +67,38 @@
|
|
67
67
|
とすると、A回転した後、B回転するようになるのでしょうか?
|
68
68
|
```C#
|
69
69
|
rigidbody.AddTorque(rotationTorque + restoringTorque);
|
70
|
+
```
|
71
|
+
|
72
|
+
### 追記
|
73
|
+
|
74
|
+
```C#
|
75
|
+
void FixedUpdate()
|
76
|
+
{
|
77
|
+
float x = Input.GetAxis("Horizontal");
|
78
|
+
float y = Input.GetAxis("Vertical");
|
79
|
+
|
80
|
+
// xとyにspeedを掛ける
|
81
|
+
rigidbody.AddForce(x * speed, y * speed, 0);
|
82
|
+
|
83
|
+
Vector3 moveVector = Vector3.zero;
|
84
|
+
|
85
|
+
//rigidbody.AddForce(moveForceMultiplier * (moveVector - rigidbody.velocity));
|
86
|
+
|
87
|
+
// プレイヤーの入力に応じて姿勢をひねろうとするトルク
|
88
|
+
Vector3 rotationTorque = new Vector3(-y * pitchTorqueMagnitude, x * yawTorqueMagnitude, -x * rollTorqueMagnitude);
|
89
|
+
|
90
|
+
Quaternion target_rot = this.transform.rotation;
|
91
|
+
Quaternion rot = target_rot * Quaternion.Inverse(this.transform.rotation);
|
92
|
+
if(rot.w < 0f){
|
93
|
+
rot.x = -rot.x;
|
94
|
+
rot.y = -rot.y;
|
95
|
+
rot.z = -rot.z;
|
96
|
+
rot.w = -rot.w;
|
97
|
+
}
|
98
|
+
Vector3 restoringTorque = new Vector3(rot.x, rot.y, rot.z) * 100f;
|
99
|
+
// 機体にトルクを加える
|
100
|
+
// rigidbody.AddTorque(rotationTorque);
|
101
|
+
rigidbody.AddTorque(rotationTorque + restoringTorque);
|
102
|
+
|
103
|
+
}
|
70
104
|
```
|