I’m making an endless runner game as a hobby project.
As part of this I wish to load in scenes additively so they’re there while the original scene is also there, and then unload the added scene after it has passed by, a bit similar to Jetpack Joyride.
Currently, the player moves at a certain speed in one direction, he jumps to survive. The camera follows the players relative position.
My issue is that when I add new scenes, I cannot get the objects of the scene being loaded to have its position relative to the player/camera, in other words it spawns at a wrong x/y position.
I have attempted using this script in each of the objects of the scene:
// Use this for initialization
void Start () {
//set position relative to camera.
Camera camera = Camera2DFollow.cam;
transform.position = new Vector2(transform.position.x + camera.transform.position.x, this.transform.position.y);
}
The issue with this script is that it seems to move the spawned objects further and further away, so first spawn works alright, 2nd spawn spawns a bit further ahead, 3rd a bit more ahead and so on.
How do i go about solving this?
Thank you for reading this and hopefully helping me resolve the issue.
Oh and please ask questions if I am not being clear enough.
Here is a picture displaying the issue, the picture shows the game paused and zoomed out, this is after the game has run for around 20-30 seconds.
