Search Unity

Linking objects X and Y

Discussion in 'Scripting' started by The-Oddler, Dec 6, 2010.

  1. The-Oddler

    The-Oddler

    Joined:
    Nov 26, 2010
    Posts:
    133
    Hi
    For a game for school I need 2 (or 3) objects linked so that one is moved the other one/two is/are moved too.
    I tried a while to get it to work, but failed :( I can get the second to move when the first moves, but the first won't move when the second moved :(

    Could anyone help me ?

    The 2 (or 3) objects should always have the same x and y, z should not change. When one is moved the other should move too and if one can't move (if it is blocked by other objects or something) neither should be movable.

    Anyone any idea how to do this ? :D

    Thanks !
    -Pablo
     
  2. Chris-Sinclair

    Chris-Sinclair

    Joined:
    Jun 14, 2010
    Posts:
    1,326
    You might be able to get by with using transform.parent, that will link the objects together. Otherwise you might be stuck getting your hands dirty scripting it.
     
  3. The-Oddler

    The-Oddler

    Joined:
    Nov 26, 2010
    Posts:
    133
    Yea, I was thinking something like that too

    But I tried to make one of the 2 objects a child of the other, and then when I move the parant the child moves too. Though when you move the child the parent doesn't (which is normal). So I wrote a script:
    but whit that the parent just flies away :( and the child stays on world 0,0,z (the childs y changes to the negate of the parent's y so that it's world y is 0).
    Any idea why that is ?

    Thanks !