[3D math, rotation] How to compute a delta rotator correctly?

Hi guys, can someone help me out with this 3d math problem?

Background:

As shown in the picture, I’d like to rotate my camera so that the crosshair will point to the center of the yellow ball. But I must do it smoothly.

Now, I got a customized angular velocity according to my formula. And I need to produce a DeltaRotator so that I can apply it to my CameraManager.

I’ve tried the following approach:

  1. Get the ForwardVector of the camera, as well as the vector from CameraLocation to BallCenter.
  2. The CrossProduct of these 2 vectors gives me an AxisVector perpendicular to them.
  3. Construct a quaternion with this AxisVector and my angular velocity(namely, the angle to rotate in the current frame).
  4. Convert quaternion to rotator as DeltaRotator, and use it to rotate my camera.

The problem is:

When the camera is facing +X axis(namely, ForwardVector.X > 0), everything works perfectly. But when the camera is facing -X axis, the Pitch of DeltaRotator is always reversed.

Why is this? Can anyone point out the mistake here? I really want to figure it out!

Thank you! Happy 2021! :slight_smile:

Follow up:

As @anonymous_user_d4b71f88_ said, I can solve this problem by interpolating from the original rotation to the final rotation. I’m just really curious about the mistake I made in the approach I posted here, cause I still feel that it seems to be correct…

Thanks again!

hi! im feirly newer to UE. but i think in your case you need just doing Spheriacal LERP with two Quaternions.
so u need

  • create Quat1 from CameraView direction (I hopeing UE math lib has helpers for that)
  • create Quat2 from Normalize(PlayerPos - BallPos)
  • Quat with result what need to apply to camera. CameraRotationOverTime = slerp(q1, q2, deltaTime * speedFactor)

Thank you! @CyberSquirrel_
Yes, you’re right. I did solve it this way, I’m just really curious about the mistake hidden in the approach I mentioned above.