Rotate physics object towards camera direction over time

Yeah everything is the same as before with the regular AddTorque node, I’m fine with making a tonne of changes if it means the end product is better.

ok… I won’t be able to help out fully, because I don’t need Yaw and Pitch for my project… so there are differences…

but basically you’ll need to download the Quaternions plugin and start using quaternions translated to vectors to get the Roll, Pitch, and Yaw error to feed into each PID. By using Quaternions instead of Rotators, you’ll avoid the risk of gimbal lock and the quick flips between Yaw/Roll as you go beyond +/-90 in Pitch. This could occur inside each PID, and in the TransformRotation and InverseTransformRotation (from world to local space). It will involve a fair amount of effort… and learning by trial and error.

Can you show me where to get the quaternion plugin.

I think it’s free on the Epic Marketplace… afaik it’s absolutely excellent

Hmm idk the only one I can see costs $5.48 for me.

sorry, my bad… I thought it is free… it is really useful though if you are doing more advanced rotation of your pawn and camera (basically… what you are doing right now). This is all fairly challenging… you are jumping in towards the deeper end.

Alright I bought it, I’ll try to do what you posted earlier.

Can you show me what you’re doing for AddTorque with your roll?

excellent question… it’s a similar expression to before (converting from local to world rotation… but in 4d quat format not 3d rotator format) but afaik without the possibility of gimbal lock…

I’m still very lost about what to do get this working for the yaw and pitch. Sorry for needing to be spoonfed through out all of this lol but I really don’t understand quaterions.
We should probably stop replying here before we cant fit letters in.

What is this madneess.##

1 Like

Lol no ideaaaaa, probably cause we keep replying so the thing keeps getting smaller, literally had to copy and paste some messages into note pad to actually read them.

Ok I got it, decided to make a separate answer so it’s not squished in that massive thread but thanks aNorthStar.
Anyway here’s the blueprint:

This works perfectly for what I need, no gimbal lock stuff.

1 Like

@everynone… LOL… you are right… madness! and UE4 physics is a flipping DEEP subject…

@seedonator… your BP is looking quite tight: you really took on a challenge… well done! A handful of suggestions though…

  • Drive a specialized MMTAddTorque and PID calcs from the special MMTTick (with the appropriate substepping settings) so it will perform similarly across different spec machines, or scale the normal AddTorque by WorldDeltaSeconds (I’ve heard this also works… maybe @everynone would comment yay or nay?)
  • Using the SkeletalMesh WorldTransform and is logically correct, it would just be better to use FromComponent to get a quat from the Skeletal Mesh and plug it directly into GetUnrotatedRotation (more efficient and better to use pure quats than ANY transforms with 3DOF movement… gimbal lock risk… afaik)
  • Your approach using Quats converted to Rotator as the error is valid… there might be a gimbal lock and flipping issue inside the PID… My current approach is to use Quats converted to Vectors as the error. But if your way works well enough, it’s great :slight_smile:
  • For efficiency, maybe store WorldDeltaSeconds (or PhysicsDeltaSeconds if you use MMTTick) as a variable, it saves you accessing it every time you use it

What are these 2 functions “Add Measured Error” and “Get Control Coefficient”?
Can you make an example project, please?