any way to access the global position and rotation of a child object?

“Object A” moves around the terrain through player input. “Object B” is a child of object A (childed by dragging on to object A in hierarchy). In the inspector, I can see The transform.position and transform.rotation of “Object A” updates as it moves around the map. However, the transform.rotation and transform.position of “Object B” does not update at all, so when I reference its values through script, I always get the same 0,0,0 no matter where “Object B” is.

“Object B” is a spawn point for a bullet and “Object A” is the FPS controller. Bullets are instantiated and moved to the transform values of “Object B” (spawn point), but they do not appear in the right place because the transform of object B does not update.

how can I access the global transform.position and global transform.rotation of “Object B”?

You can see it is still 9 milliseconds which is very small hit (16 milliseconds = 60fps). And there is not really much you can do about it. As long as you keep your code not to use more than 5 milliseconds, you will be fine. Also, it all depends on the device you are testing on.

1 Answer

1

Script Reference - Transform


transform.position - The position of the transform in world space.

transform.localPosition - Position of the transform relative to the parent transform.

transform.TransformPoint - Transforms position from local space to world space. Note that the returned position is affected by scale.

transform.rotation - The rotation of the transform in world space stored as a Quaternion.

transform.localRotation - The rotation of the transform relative to the parent transform’s rotation.

After your question I realized that I really was running make game on 60fps and the problem was I was instantiating my obstacles every 1.5 secs and they looked very laggy so I created a pool system and recycled them and that works fine now, thanks!