# AddTorqueを使ってロール軸を水平にしたい

**URL:** <https://forums.unrealengine.com/t/addtorque/638804>\
**Category:** 日本語 (Japanese)\
**Tags:** addforce, unreal-engine, UE4-27, question\
**Created:** [September 1, 2022, 9:23am UTC](https://forums.unrealengine.com/t/addtorque/638804 "2022-09-01T09:23:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![turbotanaka](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@turbotanaka](https://forums.unrealengine.com/u/turbotanaka)\
**Post date:** [September 1, 2022, 9:23am UTC](https://forums.unrealengine.com/t/addtorque/638804/1 "2022-09-01T09:23:16Z")

</div>

> [@Rotate physics object towards camera direction over time](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182):
>
> I have a jet vehicle pawn that uses physics to move and it has a camera with a spring arm. I got all the forward movement stuff working but I want to know how can I rotate the jet mesh with the Add Torque node or something to make it face the camera direction over a certain time. So for example if i look 90 degrees to the left then the jet mesh will turn to that direction over the period of 1 second.

上記トピックにある方法を使ってPawnの制御をしているのですが、ピッチを傾けた状態でヨーをかけるとPawnが横倒しになってしまいます。なのでロール軸を水平にする機能を付け加えたいのですが、ベクタの計算に不慣れでやり方が分かりません。  
物理の挙動を損ないたくないのでSetRotationのように無理矢理回転を修正したり、回転にロックをかけるのではなく、AddTorqueを使ってロールを修正したいです。どうすれば可能でしょうか。

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 1, 2022, 11:47am UTC](https://forums.unrealengine.com/t/addtorque/638804/2 "2022-09-01T11:47:24Z")

</div>

Torque works with the right vector for pitch (but it all depends on the setup, ofc). You could use forward and up vectors to achieve other rotations - do note there is a difference between adding _world_ torque and _local space_ torque. There are (inverse) transform nodes to help out here or we can unrotate a vector, too.

Also, adding torque on all 3 axis simultaneously would be very difficult for the player to control. Depending on what the end goal is, consider implementing it in a such a way that they can use 2 axis at a time only.

It gets even more difficult if you want an algorytm that can arrest angular momentum and / or produce enough counter-torque to achieve a specific rotation for a spinning body. Example of what I’m talking about:

> [@How to counter angular momentum with torque](https://forums.unrealengine.com/t/how-to-counter-angular-momentum-with-torque/503993):
>
> I’m trying to apply torque in such a way that the rotating cube (forward red arrow) arrives at the target (pink) and has its rotation completely arrested, without overshooting too much or excessive oscillations. I’m applying constant torque. As we build up angular velocity, at some point we must start producing counter-torque in order to slow down and come to a full stop. How do I detect that moment? What’s the math behind it? I feel I need to take advantage of the Inertia Tensor h…

And then you may need to look into a nested PID controller.

---

<div class="post-metadata">

**Author:** ![turbotanaka](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@turbotanaka](https://forums.unrealengine.com/u/turbotanaka)\
**Post date:** [September 2, 2022, 8:32am UTC](https://forums.unrealengine.com/t/addtorque/638804/3 "2022-09-02T08:32:18Z")

</div>

Thanks for answering my question.

I tried tilted the getted Pawn’s direction to the Z axis by 90 degrees and tried to match the Right vector.  
Unfortunaly, this method’s barely worked. A misalignment occurred and Pawn’s unable to accurately track camera orientation.

Any suggestions for improvement?
