# Rotate physics object towards camera direction over time

**URL:** <https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182>\
**Category:** World Creation\
**Tags:** unreal-engine, Physics, question\
**Created:** [April 24, 2020, 9:43am UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182 "2020-04-24T09:43:49Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seedonator](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/seedonator/32/480464_2.png) [@Seedonator](https://forums.unrealengine.com/u/Seedonator)\
**Post date:** [April 24, 2020, 9:43am UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/1 "2020-04-24T09:43:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![DavidOConnor](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/davidoconnor/32/978533_2.png) [@DavidOConnor](https://forums.unrealengine.com/u/DavidOConnor)\
**Post date:** [April 24, 2020, 10:49am UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/2 "2020-04-24T10:49:24Z")

</div>

I’ve been using the following setup to get my pawn roll to adjust to the floor beneath it (pitch and yaw are handled by the player)… it uses the MMT plugin PID controller (very simple. basically it’s a spring)… feeds in a generic error then multiplies by a factor that you manually set (needs adjustment).

If you need all 3 axes, you’d use 3 PIDS (yaw, pitch, roll)… feed in the delta between the camera’s rotation (inverted I think, because you’d like it to face the camera and not the same direction as the camera) and the player rotation (the error amount)

Then you’d convert from local space to AddTorque in worldspace (or AddForce, or AddRotation, anything)

alt text

 ![300464-add-torque-converted-from-local-to-worldspace.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/6/2/a62e6207101639bb7564f9510d50d4b99abb2cee.jpeg)

 ![300465-pid-yaw-setup.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/f/f/0ffff60701ed0c3c491ec72df4c9e93336a34ba7.jpeg)

---

<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:** [April 24, 2020, 10:51am UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/3 "2020-04-24T10:51:54Z")

</div>

I was toying with this not so long ago and wrote a full [PID controller][1], 2 in fact. And it worked but become a small nightmare to maintain.

I then played with vSpring in the engine which is a simplified PID or so I assumed, but the results were underwhelming. Or I never figured out how to use it correctly.

And then I wrote this dumbed down version which worked surprisingly well for what I needed - minimum complexity and just enough fidelity and control. It works well in 6DOF and does not interrupt any other physics forces:

 ![300453-annotation-2020-04-24-114350.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/4/3/b43f1ab7da41594516d261f6b57393d5b2ec605a.png)

[![Image from Gyazo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/3/c/e3c59079eb226324d629068c207b25147844bca6.gif)](https://gyazo.com/a3dd3a78b0b29f7522c1d65dd1fec937)

At more snappy settings, 0.0025 and 5000 respectively:

[![Image from Gyazo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/4/7/047b61847a0e699149ef36deae1d393e0c5473d7.gif)](https://gyazo.com/d0b323858dc8118607226cf60a722d70)

This does not account for time controls, you’d need to work that in. Promised myself not to touch PID-related stuff for a while.

Hope it helps at least a little.

---

<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:** [April 24, 2020, 10:52am UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/4 "2020-04-24T10:52:36Z")

</div>

Nice cross-post. I am going to look into this as soon as I recover mentally 😉

---

<div class="post-metadata">

**Author:** ![DavidOConnor](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/davidoconnor/32/978533_2.png) [@DavidOConnor](https://forums.unrealengine.com/u/DavidOConnor)\
**Post date:** [April 24, 2020, 11:14am UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/5 "2020-04-24T11:14:27Z")

</div>

thank heaven I didn’t even attempt to figure out actually writing the PID… mindboggling mindpower 🙂

---

<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:** [April 24, 2020, 11:32am UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/6 "2020-04-24T11:32:27Z")

</div>

![300458-annotation-2020-04-24-122730.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/6/0/1605d125d2dac84b3e23b6b58f3313b071a19919.jpeg)

At the core it is a glorified spring, as you said; it works but I needed it to accumulate torque over time (account for it, too) and it was right there where my _mindboggling mindpower_ failed me. 😑

Anyway, glad I could vent.

---

<div class="post-metadata">

**Author:** ![Seedonator](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/seedonator/32/480464_2.png) [@Seedonator](https://forums.unrealengine.com/u/Seedonator)\
**Post date:** [April 24, 2020, 12:09pm UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/7 "2020-04-24T12:09:24Z")

</div>

It’s pretty late for me right now but I’ll give this a try in the morning and then see if it works out.

---

<div class="post-metadata">

**Author:** ![Seedonator](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/seedonator/32/480464_2.png) [@Seedonator](https://forums.unrealengine.com/u/Seedonator)\
**Post date:** [April 24, 2020, 7:17pm UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/8 "2020-04-24T19:17:21Z")

</div>

Ok I tried it but it the mesh just spins out of control, I’m probably doing it wrong though.

 ![300500-very-bad-blueprint.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/5/0/250b74e51072f5c7e437b767ed994b134cafd217.png)

Also just for clarification, I want the jet to rotate in the same direction as the camera, so it copies its rotation basically rather than pointing at the camera.

---

<div class="post-metadata">

**Author:** ![Seedonator](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/seedonator/32/480464_2.png) [@Seedonator](https://forums.unrealengine.com/u/Seedonator)\
**Post date:** [April 24, 2020, 8:03pm UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/9 "2020-04-24T20:03:44Z")

</div>

This would work but I need the roll axis to stay the same cause other wise it wont really look good for a jet.

---

<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:** [April 24, 2020, 8:11pm UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/10 "2020-04-24T20:11:31Z")

</div>

That’s just an example, not a ready-to-go solution; I should have mentioned that. You will need to adjust it to your needs. Was going for a full 3d one. Not sure what you’re working on.

edit: do you need physics in the first place? Working with Torque is a challenge at times. Maybe you just need to vInterp / Lerp something.

---

<div class="post-metadata">

**Author:** ![Seedonator](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/seedonator/32/480464_2.png) [@Seedonator](https://forums.unrealengine.com/u/Seedonator)\
**Post date:** [April 24, 2020, 8:37pm UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/11 "2020-04-24T20:37:46Z")

</div>

I’ve tried setting the rotation to the camera rotation with the set actor rotation node but that really doesn’t work well, it allows the jet to clip through walls when it’s in a small area and also causes a tonne of jerkyness.

---

<div class="post-metadata">

**Author:** ![DavidOConnor](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/davidoconnor/32/978533_2.png) [@DavidOConnor](https://forums.unrealengine.com/u/DavidOConnor)\
**Post date:** [April 25, 2020, 5:09am UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/12 "2020-04-25T05:09:09Z")

</div>

One more thing… there are two approaches to stabilizing your physics speed across different machines… it’s a complication of working with UE4 Tick… a quite fast machine might Tick 300 times per second, a quite slow machine just 30 times per second. So you can imagine the difference in how the results would play 🙂

Use the

- Use the MMT physics plugin which will give you a regular tick, with substepping calculations. This takes a bit of understanding and setup. It’s what I use and it works very well but I’m thinking of trying the second option…
- Multiply the AddTorque by WorldDeltaSeconds… this means that your Torque amount will vary in ine with each machine’s varying tick rate… I haven’t really tested it but I’ve read good things… **Everynone** may weigh in here with a more informed opinion than mine

---

<div class="post-metadata">

**Author:** ![DavidOConnor](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/davidoconnor/32/978533_2.png) [@DavidOConnor](https://forums.unrealengine.com/u/DavidOConnor)\
**Post date:** [April 25, 2020, 5:34am UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/13 "2020-04-25T05:34:59Z")

</div>

One more thing… there are two approaches to stabilizing your physics speed across different machines… it’s a complication of working with UE4 Tick…

Use the

- Use the MMT physics plugin which will give you a regular tick, with substepping calculations. This takes a bit of understanding and setup. It’s what I use and it works very well but I’m thinking of trying the second option…
- Multiply the AddTorque by WorldDeltaSeconds… this means that your Torque amount will vary in ine with each machine’s varying tick rate… I haven’t really tested it but I’ve read good things… **Everynone** may weigh in here with a more informed opinion than mine

---

<div class="post-metadata">

**Author:** ![Seedonator](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/seedonator/32/480464_2.png) [@Seedonator](https://forums.unrealengine.com/u/Seedonator)\
**Post date:** [April 25, 2020, 5:47am UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/14 "2020-04-25T05:47:22Z")

</div>

Ok I’ve removed the multiplication of the delta seconds and adjusted the proportional coefficient.  
Also the camera is just rotated with the mouse. I made the roll stabilization very low but it still keeps building up angular velocity and then spazzes out.

---

<div class="post-metadata">

**Author:** ![DavidOConnor](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/davidoconnor/32/978533_2.png) [@DavidOConnor](https://forums.unrealengine.com/u/DavidOConnor)\
**Post date:** [April 25, 2020, 5:55am UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/15 "2020-04-25T05:55:20Z")

</div>

remember to change the Linear Damping and Angular Damping settings… this will help…

also, ensure that only one component in your Pawn is Simulating Physics

First, thing I’d suggest is to fix your control approach… are you using something like mouse Pitch and Yaw to move your pawn on these axes? If so… I can suggest something that is a bit different to your current setup, but simple and reliable

---

<div class="post-metadata">

**Author:** ![Seedonator](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/seedonator/32/480464_2.png) [@Seedonator](https://forums.unrealengine.com/u/Seedonator)\
**Post date:** [April 25, 2020, 6:01am UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/16 "2020-04-25T06:01:11Z")

</div>

Yeah I’ve set the linear and angular damping and the only thing simulating physics is the jet mesh. Also yeah im using the mouse pitch and yaw to rotate the camera, and then I want the jet to follow it.

---

<div class="post-metadata">

**Author:** ![DavidOConnor](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/davidoconnor/32/978533_2.png) [@DavidOConnor](https://forums.unrealengine.com/u/DavidOConnor)\
**Post date:** [April 25, 2020, 6:13am UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/17 "2020-04-25T06:13:55Z")

</div>

Ok! On your Player Pawn, the base class… turn off Use Pitch, Yaw and Roll… you’ll be using AddTorque to rotate your Pawn instead… Then use your mouse inputs to drive a Pitch and Yaw variable… multiplied by a suitable amount for your speed at which your Pawn will turn (I use about 100)…

Finally, add the Pitch and Yaw in your Pawn’s localspace, converting the vector to worldspace (don’t break this vector up… it’s been rotated by your Pawn’s transform). Get back here, I’m interested to ;earn how you get on

![300535-uncheck-these.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/6/c/56c7406bf4b948ea8ce9c57337fc003820255cb7.jpeg)

 ![300534-physics-controls.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/4/8/f4875654c4c3dd2d906e7a5a7da7438cf9aaf4c0.jpeg)

][3]

---

<div class="post-metadata">

**Author:** ![DavidOConnor](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/davidoconnor/32/978533_2.png) [@DavidOConnor](https://forums.unrealengine.com/u/DavidOConnor)\
**Post date:** [April 25, 2020, 6:22am UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/18 "2020-04-25T06:22:13Z")

</div>

oh… this bit might be useful…

 ![300537-pitch-and-yaw.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/3/4/834210cb899a056de5648ca520d23d1b4cc854c7.jpeg)

---

<div class="post-metadata">

**Author:** ![Seedonator](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/seedonator/32/480464_2.png) [@Seedonator](https://forums.unrealengine.com/u/Seedonator)\
**Post date:** [April 25, 2020, 6:26am UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/19 "2020-04-25T06:26:05Z")

</div>

I don’t think we’re on the same page, the actual pawn isn’t being rotated by the controllers pitch, yaw and roll, the camera is being rotated though. Without the Add Torque node the pawn won’t rotate. I need the pawn to rotate into the same direction as the camera with torque.

---

<div class="post-metadata">

**Author:** ![DavidOConnor](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/davidoconnor/32/978533_2.png) [@DavidOConnor](https://forums.unrealengine.com/u/DavidOConnor)\
**Post date:** [April 25, 2020, 6:33am UTC](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182/20 "2020-04-25T06:33:28Z")

</div>

ah… alright then… for your setup, you’d need 3 MMT PIDs, one each for pitch, yaw, and roll…

[Next page](https://forums.unrealengine.com/t/rotate-physics-object-towards-camera-direction-over-time/464182.md?page=2)
