Need help to get 3D rotation from 2 points in space

This might have been answered already, but I’ve read many topics about rotations this afternoon and didn’t manage to make it work (I’m terrible with 3D transformations…).

I have:

  • 2 points in space: pointA and pointB.
  • a cube which I want to be connected to both points.

So far, I managed to place my cube right inbetween my points, and scale it on the X axis by the distance between these 2 points. Now the last thing I need is to manage to rotate my “cube” so that both ends of the local X axis end up on my 3D points.

I’ve tried using the lookout(), using the eulerAngles and many other different ways, but I just couldn’t get anything because I fail transferring the math found on some related answers to my specific need.

Can anyone help me please?

v3Pos1 and v3Pos2 are the two point:

transform.rotation = Quaternion.FromToRotation(Vector3.up, v3Pos2 - v3Pos1);