Matching rotation of random objects

I am trying to create a randomly generated pipe, built of two pieces a strait and a turn, both of these have been imported from maya. Every update, I instantiate a new strait or turn, I use the position of a spawn point slightly in front of the object, then try to rotate it to match. The problem is with the turns, I can’t find a good way to match the rotation of it. So I’d thought I’d ask some people who are smarter then I am if they have any good ideas, well?

I’ve thought about putting an empty object at the mouth of the turn, then wrap the strait in a second empty object, and call LooAt. But I’d really rather not have to work with yet another two empty objects.

This is what it should look like, but for any possible rotation of the turn.

2762-turnandstrait.png

You should know the pipe’s rotation since you built it. Let’s assume the origin of the objects is the leftmost side in that image, and that the turn is 30*.

You just placed a turn, and now you want a strait. Place the strait in the same place as the turn, then rotate it by the turn’s angle (30*) around the pivot of the turn (where the left and right flat edges of the turn would meet). That should create the image you have there.

Get the change of rotation from going straight to the new direction of the rotation, and apply the inverse of that rotation to the new piece being instantiated.

Delta(positionNew) = oldPosition(x,y,z)

place some blocks in ur scene view manualy then check ur local rotation to see how it fits ur turn and in ur script when u know the next gameobject is a turn have that + localrotation stored in a value and use it + the localrotation of ur last object this way if u place 2 turns in row it will fit automaticaly. i don’t know if im explaining myself correctly but it should work.

srry for the bad english xD