Search Unity

Wrong world position

Discussion in 'Scripting' started by Nihil688, Aug 31, 2015.

  1. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    Dunno if anyone else had this but when I parent a object on a humanoid animated character, the "transform.position" returns the wrong position ( tested in 5.1.3 ).

    If I pause the editor, unparent and redebug it says the right position but as long as it's parented it wont, any ideas?
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    You aren't looking for transform.localPosition instead?
     
  3. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    I want to instantiate a bullet at the tip of a gun and when that gun is parented to the hand of the character the world position is wrong and the bullet gets instantiated at the center of his body instead. If I unparent it then the world position works fine
     
  4. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    I fixed it with a hack by adding a monobehaviour on the tip and stored the position in a variable, that way it provides the correct position information, someone has to look into this one...
     
  5. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    I tried to reproduce this behaviour but everything worked as it should.
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Sounds like you are simply grabbing the wrong transform.
     
  7. Nihil688

    Nihil688

    Joined:
    Mar 12, 2013
    Posts:
    503
    @Suddoha how do you create the weapon in the hand? If you have done this with a monobehaviour then it'll have the correct result as my solution which aren't an answer as to why transform.position doesn't work at all times

    @BoredMormon I have the object and I do .transform.position, I don't see how this can be wrong, also when I'm unparenting on the same second without changing any code the result is correct.
     
  8. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    I simply created 2 objects, one being the child of the other. I placed them manually. The only thing i've done with scripts is a Debug.Log() and it always prints the position to the console that i expect.
    Sorry if i misunderstood something.
    Maybe you could add some pictures/screenshots and your script?