Generating prefabs at origin that are children of moving GameObjects?
This image may be a little confusing, I'll try to describe it the best I can:
Red = CloudGenerator (GameObject) Blue = Cloud (Prefab)
Goal: I'm trying to generate clouds at the horizon and have them move towards the player
Currently: I have a scene set up so that the CloudGenerator is moving towards the camera and and every half second or so, it generates a new Cloud prefab at 0,0,0 (to simulate the horizon). These prefabs are parented to the CloudGenerator so that they all move at the same speed.
Problem: The Cloud prefabs are being generated at the LOCAL 0,0,0 point, so as time is passing, the clouds are all clumping together and moving as one lump of cloud.
Question: How can I generate the Cloud prefabs at the WORLD 0,0,0 coordinate, but still have them move in unison as a child of the CloudGenerator GameObject?
Thanks in advance!!!! :D
Answer by HenryStrattonFW · Nov 17, 2015 at 06:29 PM
After you instantiate the cloud, you can access its transform and just set the transform.position value, which will be relative to the world, where as transform.localPosition will be relative to its parent (which if no parent i believe just acts as the world position anyway).
Answer by teodoro4 · Nov 17, 2015 at 06:50 PM
Thank you so much. I added that bit of code at the end and it has fixed the problem. The only concern I have is that if the game is running slowly, they may see this jump in position? I haven't encountered it yet, but I'll report back if I do.