Aligning boxes rotation to face a object

I am attempting to create a script which will create a row of boxes, going from one point to another(both chosen objects).
The (first) attachment shows what I have at the moment, and the second(manually rotated) shows what I'm trying to get(the reason the boxes aren't inbetween the two boxes, but offset is because the pivot is still in the center, not at the end).
I have managed to get the positions correct, but haven't been able to get proper rotations.
Any help would be appreciated, I have been trying for a while, and havent managed to get a properly working result.
Edit:
I have also tried using a look at constraint, but haven't been able to transfer the objects rotation to the others, and I don't want to add the constraint to every box.

AttachmentSize
problem1.png17.23 KB
problem2.png19.14 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Swordslayer's picture

Something like this would be

Something like this would be a way, of course this is just one of many solutions and probably the most stupid one, but good as a starting point nonetheless.

fn rotateBox b p1 p2 =
(
	local x = normalize (p2.pos - p1.pos)
	local y = cross z_axis x
	local z = cross x y
 
	b.transform = matrix3 x y z b.pos
)
 
rotateBox $Box001 $Point001 $Point002
brttd's picture

Thanks! It works well (only

Thanks! It works well (only had to change round the x & y(the boxes were overlapping)), Im not that knowledgeable with stuff like this so thanks again.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.