Hey Guys,
id like to align a cube to a line. For example: i draw a line with x0/y0 and x1/y1…
Now i wanted to align a cube to this line. It should have the same size, the same rotation and the same location.
How could i do this?
thanks
Hey Guys,
id like to align a cube to a line. For example: i draw a line with x0/y0 and x1/y1…
Now i wanted to align a cube to this line. It should have the same size, the same rotation and the same location.
How could i do this?
thanks
i got 1 line. with a start coordinaten and an end-coordinte (x0/y0 and x1/y1).
And id like to align a cube (for example) to this line. With size, length, rotation…
I solved it partially…
//set line ends to vectors
Vector3 vecA = new Vector3(data.line_.x, 40, data.line*.y);*_
Vector3 vecB = new Vector3(data.line_.x1, 40, data.line*.y1);
//get our midway point*
Vector3 midPointAB = (vecA + vecB) / 2f;
//get the direction between the two transforms →
Vector3 dirAB = (vecB - vecA).normalized;
// get the rotation of the line
//Vector3 relativePos = vecA - transform.position;
Quaternion rotationAB = Quaternion.LookRotation(dirAB);
// get the length of the line
Vector3 abLength = vecB - vecA;
line.transform.localPosition = midPointAB;
line.transform.rotation = rotationAB;
// set the new length (scaling size from cube prefab is 1/80/1/)
line.transform.localScale = new Vector3(line.transform.localScale.x, line.transform.localScale.y, abLength.z);
But it doesnt work perfectly because the scaling is wrong, in relation to the direction.
So i try since 10minutes with magnitude to solve it._