# How can I rotate a cylinder so the top points at specific transform?

I have a GameObject (goA) with a LineRenderer that has a single line drawn, on which I'd like to place cylinders so the top of the cylinder points to each end of the straight line that the cylinder sits on, (similar to a cylindrical bead on a straight piece of string, or a Candlestick chart).

The cylinder GameObject (goB) is a child of the goA which the LineRenderer is sat on (goB.transform.parent == goA.transform).

goA is not rotated itself, and the Line drawn could be any angle relative to the GameObject, and it would be a bit of a hassle to refactor so that the Line is always vertical and instead rotate goA, and it seems this should be an easily solvable problem!

I'm attempting to use either LookRotation or LookAt on the cylinder but for whatever reason all permutations I can think of simply are not working.

• I'm just going to ask out of curiosity - why are you needing the LineRenderer to create the cylinder; what is the inspiration behind doing it in this particular way? Commented Feb 24, 2020 at 9:51
• @Tom'Blue'Piddock sorry maybe I'm unclear, the LineRenderer draws a line on one GameObject (A), and the cylinder is on a second GameObject (B). They are only connected by B.transform.parent == A.transform
– DanH
Commented Feb 27, 2020 at 10:28

var direction = endTransform.position - startTransform.position;

var orientation = Quaternion.FromToRotation(Vector3.up, direction);