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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Direction is reversed child created game object

Discussion in 'Scripting' started by noatom, Apr 10, 2014.

  1. noatom

    noatom

    Joined:
    Apr 9, 2014
    Posts:
    21
    I have an object which has 2 components: one that moves it to the left, and one that creates another object, which should move to the left.

    The main sprite moves to the left alright, but once the second object is created, it moves to the right.

    Both of them have as direction set by default: -1. So the final velocity ends up being -1 * 5(speed) = -5

    I read a little and found out that I should just rotate the second sprite(the one going right instead of left) by the Z axis at 180 degrees.

    My simple question is: why is the main object moving to the left, and the second object moving to the right, when in the end they both end up with -5 velocity?!
     
  2. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    its a matter of relativity.

    Object 1, moves left because it's forward direction points away from you.
    Object 2, moves right because it's forward direction points towards you.

    Both objects move to their left.
     
  3. noatom

    noatom

    Joined:
    Apr 9, 2014
    Posts:
    21
    and why is that if i may ask? why would the second object be rotated 180 degrees, and not be put in the exact same position and orientation as the first one?!
     
  4. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    the rotation is the key. If both were facing away, both would move the same "left", stand up, look at the wall, and move left..... go back to the same position, look away from the wall and move left.... do you wind up in the same spot?
     
  5. noatom

    noatom

    Joined:
    Apr 9, 2014
    Posts:
    21
    I still fail to understand how this helps the programmers at all.
    Also, your explanation doesn't make sense to me. If I have a book and I want to put another one on top of it, wouldn't I put them so both of them would have their front down, and their back up?

    I just fail to see why this was implemented this way at all.
     
  6. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    again, its relativity.

    2 cars. at the same place, one faces east, one west.

    Both cars drive 1 mile.

    So now the cars are 2 miles apart.

    If both face the same direction, and drive 1 mile, they are still together.

    If you don't turn one around, it never goes the opposite direction.



    Ah, the "why is this done this way"

    This is simple. I write 1 piece of code to make it move left. or 2 pieces of code, one to make it move left, the other to make the second move right. It's a simplification of the same motion. Left, is left, but relativity says Left can also be right. Depending on your perspective.

    The second perspective says... If I write 1 piece of code, it takes me 1 hour, if I have to rewrite a second piece of code it takes me 2. I would rather not waste the time when relativity allows me to save it.
     
    Last edited: Apr 10, 2014