Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Placing Tubes at child points

Discussion in 'Editor & General Support' started by twick, Aug 7, 2014.

  1. twick

    twick

    Joined:
    Nov 16, 2011
    Posts:
    31
    I am looking for advice on making a system that would accurately put pipes/tubes together at points during runtime. I already have the models that vary in length and width (Tube radius is mostly the same). This is being done in 3d and should be able to build in any direction.

    I already have a way to accurately place a child object at the ends of the tubes and even render out a dynamic tube. I want the player to be able to click a point and place a pipe that would attach to the side accurately. I get the world Vector3 position of the points I want to connect together but its not really coming to me how to appropriately attach them together.

    Any advice for going about this correctly would be wonderful.

    Hierarchy of a tube :
    - Tube1
    -- side1
    -- side2

    Tubes have a box collider. (But its not required)
     
  2. twick

    twick

    Joined:
    Nov 16, 2011
    Posts:
    31
    Bump
     
  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    This is not an easy one to solve, but could be easier if you can put some restrictions on the tube's endpoints. For example, will they always be at right angles? Will they always be a certain distance apart (or rather a multiple of a certain distance apart, effectively on a grid system)? If either of these answers is 'no', the system gets a LOT more complicated. If they're both 'yes', then the challenge is really to pathfind from point A to point B and then figure out the proper pieces to use along the way.
     
  4. twick

    twick

    Joined:
    Nov 16, 2011
    Posts:
    31
    Actually the user would be picking a tube and a side to place it on.
     
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    Then I've apparently misunderstood the situation. I thought you needed tubes to connect two objects to each other.
     
  6. twick

    twick

    Joined:
    Nov 16, 2011
    Posts:
    31
    Sorry. Really seems like I am over complicating things. Its just picking a tube (Could be angled), than a side of another tube, and connecting them together. I already have the Picking of the tube worked out. I am using Tuberenderer to create the tube, just need a good way of connecting them together.

    I guess its mainly figuring out rotation thats getting to be an issue.
     
  7. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
  8. twick

    twick

    Joined:
    Nov 16, 2011
    Posts:
    31
    If I could manage something like that, that would be ideal! The main issue I have is I am not just using straight pipes, they could be straight and turn 45 Degrees. Like below except the length and angle are variable.
     
  9. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    OK, now I understand your goals.

    The simplest thing I can thing of in this case: Abuse the hell out of the hierarchy to make it do what you want. You COULD accomplish the same thing by transforming vectors and quaternions, but that gets complicated real quick, and using the hierarchy gives you a nice visual method of finding problems.

    You have two pipes, A and B, which each have connection points, let's call them X and Y, represented as transform children of the pipe. The connection points should be orientated in a consistent fashion, so that, for example, point AY has its "x-right" vector pointing outward, and point BX has its "x-right" pointing inward. In other words, if you perfectly match BX's position and rotation with AY's position and rotation, A and B will appear connected.

    "But how do I make BX's position and rotation match AY's?" There is where hierarchy abuse comes in. Unparent BX from B, and then (without moving anything in between) set B as a child of BX. Now, set BX as a child of AY, and zero out BX's local position and rotation. Now that they're in the right place, you may (should you so desire) undo all the parentage changes you've just made.
     
  10. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    Outside of that, your biggest challenges will probably be:
    A) figure out where the player is trying to click - I recommend transforming end "unused" endpoint to screen space, checking the distance to the mouse pointer (remember to zero out the Z coordinates), and using the closest one.

    B) Rotating parts on connection, so that your single L-joint pipe can make an up-facing pipe turn north, south, left, or right. Best thing for this is probably to simply rotate BX around its X axis (if you use the orientations from my example) at the end of the process, just before you undo all the parentage changes.