I have to check in a gameobject and a plan that the normal of the plane is equal to the direction “up” the game object. How can I do? this is what I’m doing.
Are you trying to have ‘plane’ stand straight up on the surface that it’s standing on? So that it’s up vector equals that of the surface it’s on?
So you’ll want to maintain the same general forward direction, but use this new up.
Well you can use cross products for that. If we take the cross product of the current forward with the desired up, we’ll get a vector that is orthogonal (perpendicular in 3-space) to the forward and up. Then if we take the cross of that with the desired up, we get the orthogonal of that which would be the new desired forward that is orthogonal to up.
Now if we stick that into the Quaterion.LookRotation, we get the rotation we desire:
var n = *the up we desire, from the normal*;
var f = plane.transform.forward;
f = Vector3.Cross(Vector3.Cross(n, f), n);
var rot = Quaternion.LookRotation(f, n);
plane.transform.rotation = rot;
If you want to ease towards this new rotation, use Quaternion.Slerp:
var n = *the up we desire, from the normal*;
var f = plane.transform.forward;
f = Vector3.Cross(Vector3.Cross(n, f), n);
var rot = Quaternion.LookRotation(f, n);
plane.transform.rotation = Quaternion.Slerp(plane.transform.rotation, rot, 0.5f);