Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

Infinite runner world creation

$
0
0
Hey people,can someone help me on scripting this.I'm doing this like subway surfer,keeping player stationary and moving the world around him.My question is how can i instantiate the track prefab continuously right after previous one..? ![alt text][1] For instance I have track named Track_A as prefab and as soon as this track is instantiated in the world, a script attached to it will make it move.I instantiate 5 prefabs at start-up one after another tailing perfectly. When the first track is destroyed after reaching a certain point,it will get destroyed and a new track will be instantiated at the end of the chain but will cause FLOATING POINT PRECISION ERRORS leaving small gap between track prefabs.HOW CAN I SOLVE THIS..? I am attaching the script with this **TrackScript** //The length of the track (will be predefined and same for all track) public float tracklength=10; //The speed at which the tracks are moving private float worldspeed=10.0f; void Update() { //Move the new track towards the camera transform.translate(-Vector3.forward*Time.deltatime*worldspeed); } //Function to get the end of this track to create the next track public Vector3 GetTrackEndPos() { Vector3 Endposition=transform.position; Endposition.z+=tracklength; return Endposition; } **WorldScript** //This function will be called when a track at player end is destroyed to create a new track ahead of the last track public void CreateOneTrackAhead() { if(LastTrackPrefab) {Pos_TrackInstantiate=LastTrackPrefab.GetComponent().GetTrackEndPos();} //Instantiate the track at the end of previous track LastTrackPrefab=Instantiate(TrackPrefab,Pos_TrackInstantiate,Quaternion.identity); } [1]: /storage/temp/22033-preview.jpg

Viewing all articles
Browse latest Browse all 7934

Trending Articles