I want to create an object that always points towards gravity. Imagine a compass, but instead of being magnetic, it has a weight on one end of the indicator. Tilting this compass slightly would make the weighted end point "as downwards as possible" with the given rotation plane (which would be the compass's face).
So essentially I have a rotation plane defined by a normal vector around which I can rotate my indicator vector. The indicator vector is perpendicular to the normal vector. Then I have a target vector to which I want to get as close as possible, in this case, this is my gravity vector.
I want to get the result in either a rotation matrix or in a quaternion.
I have found this question where the accepted answer seems to be what I seek but after implementing it I tested it with the simplest case: rotation axis parallel to the ground and rotating the object around the rotation axis. I got okay results for angles between 80° and -80°, but with 90° or more my indicator starts moving all over the place for some reason.
So at this point, I'm unsure if the solution is what I seek so I hope someone could confirm to me that the solution given in the other question can be applied to my case or, if not, point me in the direction of the solution I'm looking for.
A 90 degree angle corresponds to the weight of the “compass” being held vertically at the top. The weight can fall in either direction (CW or CCW) with no preference. Unless you tell your simulation which way you want it to fall in this special case, you’re going to get weird looking answers.