Search Unity

Two object's y axis look same way?

Discussion in 'Scripting' started by Gokcan, Jun 18, 2018.

  1. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    200
    Hi All

    There are two cubes in my scene. Lets call them cube1 and cube 2. I want cube2's y axis always looks the direction of cube1's y axis. And within that direction I should be ableto rotate cube2 around y axis. To do it: In update method I call:
    cube2.transform.up=cube1.transform.up;

    This line of code does first requirement. However I cannot freely rotate cube2 around its y axis!!! Please help me guys. I did so many thing and could not do it.

    NOTE: I dont want any parent child solution...

    Thanks
     
  2. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,593
    Of course you can't - because of your requirement. :)

    Either Cube2 has it's own rotation, or it is fixed (as per your line of code) to a given value. It can't be both at the same time.

    I wonder whether your requirement is actually : "when a change occurs in the rotation of Cube1 around its local Y axis, a similar adjustment should be applied to the rotation of Cube2 around its Y axis". If that is the case, then you would want to record the delta for Cube1's rotation and add that delta to Cube2's rotation.
     
  3. Gokcan

    Gokcan

    Joined:
    Aug 15, 2013
    Posts:
    200
    Hi @Doug_B
    Lets say yes: when a change occurs in the rotation of Cube1 around its local Y axis, a similar adjustment should be applied to the rotation of Cube2 around its Y axis.

    So my requirement is simple: only y axis looks same direction with cube 1 and in editor I can change cube2 around y axis since it does not change its y direction so that they are looking still same direction:)
     
  4. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,593
    Ah, I see. :)

    You could try this solution given here. It sounds like what you are wanting.