I'm working on a project where you can draw lines between points. You select one point and drag the mouse onto another point and a line is drawn between them.
The line itself is a 3d object which is scaled to match the length between points. Currently you can draw lines that are horizontal or vertical. But drawing a line that starts and ends on a different level fail.
Horizontal and vertical work well.
Here the lines should go like indicated by the grey lines. But it adds the Z-rotation(Up/down) to the Y-rotation(direction) - (Setting the Y-rotation by hand to match the horizontal line results the line being drawn correctly).
Vector3 dir = junctionFinderHit.transform.position - startPos; /// Direction vector float angleY = Vector3.Angle(dir, new Vector3(1, 0, 0)); float angleZ = Vector3.Angle(dir, new Vector3(0, 1, 0)); //Debug.Log(angleY + " - " + AngleDir(new Vector3(0, 1, 0), dir, Vector3.up)); Vector3 rotationVector = new Vector3(0,0,0); if (AngleDir(new Vector3(1, 0, 0), dir, Vector3.up) < 0) /// 360 movement instead of 180 rotationVector.y = 360-angleY; else rotationVector.y = angleY; /// -90 degrees to make it horizontal by default, negative to make it point to the right direction rotationVector.z = (angleZ-90f)*-1; activeStick.transform.eulerAngles = rotationVector;
What do I need to do to get the rotations correct?