When you set a player directly above the world and you set it’s rotation to look at the world (0, 0, 0) then when the player passes directly above the world it will rotate and keep staring at the world, but is there a way to keep the orientation of the player still facing forward while staring at the world?
Example:
World = A Large Box centered at (0, 0, 0)
Player = A player standing on top of the box ex: (0, 0, 10)
When the player goes from (1, 0, 10) → (0, 0, 10) → (-1, 0, 10) the player will rotate around 180 degrees, which I do not want. I want the player to keep facing the forward direction he originally was while still staring at the center of the world.
Determine an arbitrary “up” direction (by default this can be Z, but you can choose whatever you want)
Determine the “forward” vector you want.
Generate a “right” vector by crossing “up” with “forward”
Generate a new “up” vector by crossing “forward” with “right”
Normalize the vectors
You now have a right/forward/up left-handed basis that you can plunk into a matrix to make your orientation
You get the problem you describe when you “forward” equals “up” (or negative “up” – technically, they become linearly dependent.) The easiest way to fix that is to detect that the cross product between up and forward is very small. When that is the case use an “alternate up” vector – perhaps one that’s sqrt(0.5)*(Y+Z) instead of just Z.
There will still be a discontinuity around the area where you decide to switch up vector. You can make this softer by lerping between the two up vectors based on how close to singular you are.
If you want a physics type scenario of this it would be the hairy ball theorem. it comes down to the fact how you can’t fully comb a hairy ball to all go in one direction. There will be a south and north pole where the hairs contradict. The same thing is happening in my case where when the player reaches the north and south pole the camera will do a full 180 degree rotation.
I may have been unclear what I wanted but, it suppose to be a top down view of my player who is circling a box(planet). The camera would follow it perfectly with a simple look at feature, but when it hits the north and south pole, the camera does a flip.
Hi @jwatte, seems like you know your math, so this approach you describe. Is there any chance you can create a BP that does that? I currently only have two points (positions of two motioncontrollers for VR). Do i use that vector between those two points as forward vector? and just use z-axis as up vector as default? If so, then i got that part done, but then you lost me when u said, i can plunk those into a matrix to make my orientation? Do you mean “Make Rotation from Axes”?
This btw, does NOT work. It still flips out at forward pointing up, and actually makes the orientation jitter around, probably because the up-vector changes constantly. And also the axes are flipped once i move one controller behind the other. See recording here: