I have created an empty GameObject in which I have put a couple of child GameObjects.
Now I need to find out the real position of the childs. If I move / rotate the parent GameObject the positions of the childs won’t change.
I have tried:
x = ChildElement*.gameObject.transform.localPosition.x* and x = ChildElement*.gameObject.transform.position.x* but the values are always realtive to the parent GameObject. The parent GameObject can rotate and I need to find out which child is on top while rotating. Please can you help me? Thank you, Ulrich
I also thought this. But “ChildElement*.gameObject.transform.position.x” will always give the same coordinates while rotationg the parent.* Now I’m doing: x = ChildElement*.gameObject.transform.localPosition.x + Parent.gameObject.transform.localPosition.x;* and this works fine…
As stated, Transform.position should always give you the world position.
I don’t have a link, but someone posted a thread just like this a while back. They stated that Transform.position was returning the local position, and several people pointed out that it should in fact always return the world position. It then turned out that there was a problem with the OP’s diagnostic and that Transform.position was in fact functioning correctly.
So, I’d double-check everything and make sure you’re actually printing out (or whatever) what you think you’re printing out. There really should be no need to compute the world position manually like that; Transform.position should work just fine for this.
I’m also having the same problem. Setting the position to (0,0,0) doesn’t work - I have to set it manually in the inspector, as confirmed several times. I’m using the code:
ObjectSelected.transform.position = new Vector3(0,0,0);
transform.position is supposed to set the global position, but it doesn’t always do that. The odd thing is that it was working yesterday, and I didn’t change that part of the code.
I have the same problem, whatever I do it it keeps giving me the transform of the parent, Its driving me nuts.
I have 2 movement fields, the parent moves with a scrolling movement and inside you control the movement of a child object.
You all keep saying Transform.position is the global position, but that is not fixing the issue.
I am having the same issue. Transform.position is only returning the local position, not the world position.
EDIT: OK, so the Transform.position DOES return the global/world position.
+My problem is that I was using my code in a method that was not getting called, so I moved my code to the Update method and it worked perfectly!
Can anyone please explain to my why Unity is such an absolutely unintuitive piece of underdeveloped garbage?
This is not the first time I waste my time using its’ features and assuming they work just like the documentation says just to bring myself to a scalding, raging headache because I discover after days of work that the bug I was searching for in my code is not actually there, but it is some basic feature that does not work as it claims to.
Hierarchy has 4 cubes. One has script attached. Script holds 3 of the cubes. Accessing their position and drawing a ray upwards locally works, as well as from script gameobj, but no matter what I do, nothing (none of the point transform bullshit either) works to draw a simple debug ray between the script gameobj and said cubes. Best I`ve gotten is some random lines from the script gameobj origin into a single direction diagonally as if some kind of multiplied local position of children has been given to it. Local, world, parented, unparented, nested, whatever. Nothing gives a simple. fucking. line. between. two. referenced. objects. in a script. god. why?
You didn’t bother to understand that DrawRay draws rays. Not lines. Different thing. DrawLine draws lines. Exactly like the docs say. Nice unhinged rant though. Take responsibility next time instead of blaming tools for your own lack of understanding. Not to mention your post was an off-topic necro.
im having an issue when detecing heigh fall of y position when the character enter into a kind of elevator, he become to be children of it so it moves along y axis, then if i fall just moving away. my ground detector doesn’t seems to get correctly the last transform.position.y of my character :S anyways if i jump its seems to do it correctly probably i have something wrong on my codes that’s for sure hehe