Given a start point and start rotation and end point and end rotation, how can i find a path from start to end, that takes rotation into account and moves only on the axis. I currently have a code that can handle straight line and a L turn. I want it to be able to handle also S or U turn (like on this image), but i cant figure out how to do it. Below is my current code for handling the pipleine building.

How do different games handle that? Like satisfactory fluid pipes on vertical mode.

 Vector3 endPos = endPosition;
        Vector3 startPos = startPosition;
        Vector3 dir = startRotation * Vector3.forward;
        Vector3 diff = endPos - startPos;

        Conveior prev = startTarget;
        int dist1 = Mathf.RoundToInt(Vector3.Scale(diff, dir).magnitude);

        BuildStraight(dist1, ref startPos, dir, startRotation, ref prev);
        Vector3 endDir = endRotation * Vector3.forward;
        GameObject temp;
        if (dir != endDir)
            temp = GameObject.Instantiate(turnRight, startPos, Quaternion.AngleAxis(Vector3.Angle(prev.transform.right, endDir), dir) * startRotation);
            temp = GameObject.Instantiate(straight, startPos, startRotation);
        Conveior t = temp.GetComponent<Conveior>();
        if (prev != null)
        prev = t;

        diff = endPos - startPos;
        int dist2 = Mathf.RoundToInt(Vector3.Scale(diff, endDir).magnitude);
        startPos += endDir;

        BuildStraight(dist2, ref startPos, endDir, endRotation, ref prev); 
        if (endTarget)

    private void BuildStraight(int distance, ref Vector3 startPos, Vector3 dir, Quaternion rotation, ref Conveior prev)
    for (int i = 0; i < distance; i++, startPos += dir)
        GameObject go = GameObject.Instantiate(straight, startPos, rotation);
        Conveior c = go.GetComponent<Conveior>();
        if (prev != null)
        prev = c;
  • \$\begingroup\$ Answer keyword: Bezier Curves \$\endgroup\$
    – Weckar E.
    Aug 12 '20 at 13:57
  • \$\begingroup\$ How do i aling the points on a curve to a grid? \$\endgroup\$
    – Marko Taht
    Aug 12 '20 at 15:49
  • \$\begingroup\$ A Bezier curve is forced to always go through its anchor points. So by putting those on the grid, the curve will go through those points. \$\endgroup\$
    – Weckar E.
    Aug 13 '20 at 4:16
  • \$\begingroup\$ I get what you are saying, but beziere line is not what i want. The pipeline must move along the cardinal axes. \$\endgroup\$
    – Marko Taht
    Aug 13 '20 at 7:24
  • 1
    \$\begingroup\$ The issue come from the fact that if i have multiple L turns. Then how do i determine to which side must i turn? I have only the heading of current element, and end position. What would be a good formula or algorithm to determine, should i go up or down, left or right? I cant use the rotation of the end because start and end can share rotation. And as you can see the initial heading is determined by the starting element. So it might be in any direction. \$\endgroup\$
    – Marko Taht
    Aug 13 '20 at 17:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.