Stick one end of GameObject to Camera

Hello,

I have a Prefab which I Instantiate at a given Position (It’s a capsule like Object). Now I want the Capsule’s one end to Stick to the Point I just Instantiated It to and the other end, I want to stick to in front of my camera(I’ve got this Point already). How do I split a GameObject to do this or which Magic do I have to do with the Scale and Rotation Vectors?

For starters, you know 2 points. lets just call them start and end.

One of the cute things about Unity is that you can force a direction.

Vector3 direction = end-start;
Vector3 middle = start + direction * 0.5;
object.position = middle;
object.up = direction;

Thanks for the reply but there is one problem left, how do I scale the capsule lengthwise? It should be getting longer.

easy… I was wondering all that too… you scale it, by first knowing that the capsule is 2 units in height. (very important)

object.localScale = new Vector3(1,direction.magnitude / 2,1); // remember 2 units in height to begin with.

Sweet, thank you.