Hey,
In the app I am making the user places objects on the ground and a line is supposed to appear between them, so that they are connected. I managed to instantiate and scale it correctly but when it comes to rotation… after a few hours I still cannot figure out how it should be. The endpoints’ coordinates can be different in all axes - they are not in the same plane. Here’s my funtion:
void PlaceLine(Vector3 startPos, Vector3 endPos)
{
// calculating the center point between two endpoints
Vector3 centerPos = new Vector3(startPos.x + endPos.x, startPos.y + endPos.y, startPos.z + endPos.z) / 2f;
// instantiating the line in the center point with an appropriate rotation
GameObject line = Instantiate(linePrefab, centerPos, Quaternion.FromToRotation(endPos, startPos));
// calculating the scale of the line
float scaleX = Mathf.Abs(startPos.x - endPos.x);
// setting the line's length
line.transform.GetChild(0).localScale = new Vector3(scaleX, 0.001f, 0.03f);
}
I’ve also tried using Quaternion.LookRotation and some other ways but none of them worked for me either. I don’t like quaternions and they don’t like me, I guess…