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:
- Get the
ForwardVector
of the camera, as well as the vector fromCameraLocation
toBallCenter
. - The
CrossProduct
of these 2 vectors gives me anAxisVector
perpendicular to them. - Construct a quaternion with this
AxisVector
and my angular velocity(namely, the angle to rotate in the current frame). - 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!
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!