The best way to explain this would be, Imagen you have two spheres and a line connecting them, ( o----o ), how would I make sure, that even when I move one sphere up, that the line will still be connecting them?
Here is a bit of code I posted in a different context today.
#pragma strict
var goStart : Transform;
var goEnd : Transform;
var factor : float = 1.0;
function Start() {
SetPos(goStart.position, goEnd.position);
}
function Update () {
SetPos(goStart.position, goEnd.position);
}
function SetPos(start : Vector3, end : Vector3) {
var dir = end - start;
var mid = (dir) / 2.0 + start;
transform.position = mid;
transform.rotation = Quaternion.FromToRotation(Vector3.up, dir);
transform.localScale.y = dir.magnitude * factor;
}
You need to drag and drop the start and end game object into goStart and goEnd. I believe the factor for a cylinder is 0.5.
That’s greate!