Realign Object

Ok, I searched the forum but I see no answers. I have an object at world coordinates 0,0,0 that exerts gravity on a player object. The player object can be anywhere around that world point, but I always want the “bottom” of the player object to point to the center of the gravitational source (at 0,0,0). The catch is that I DON’T want the object to FACE point (0,0,0), but instead bring its “down” vector into alignment with it the shortest way possible, without rotating the object on its local x,y plane (around the local Y axis) … hope that makes any sense. :confused: I don’t know Unity enough to figure out how to do this the way I want. I got close, but not 100% (can’t post the code sorry, I already change it in trying something else).

… and no, I don’t want to use the physics engine to do this for special reasons, thanks …

Ok, never mind, I figured it out myself. :stuck_out_tongue:

If anyone is interested, this is the final code I came up with, and it works perfectly! (so far anyhow)

// ... get axis between the object's "down" vector and the gravitational force ...
Vector3 axis = Vector3.Cross(-transform.up, objectGravity.GravitationalVector);
// ... get angle difference between the same two vectors ...
float angle = Vector3.Angle(-transform.up, objectGravity.GravitationalVector);
// ... apply needed rotational push to realign upright ...
transform.RotateAround(axis, angle * RealignDampening); // (0.001f works good)

Now I just have to get the camera to behave to all this. :wink: