- Home /
How to create an endless track?
Hello everybody!
I'm creating a game where i need an endless track. I've got a object, which moves always in z-direction. Now the script should generate a track for the object to move on. It should work similar to this project: http://catlikecoding.com/unity/tutorials/runner/ how the background is generated, but in JavaScript.
I hope that anyone can help!
Doooode, that tutorial most likely has everything(though primitive) that you would need, just not in Java/Unityscript, i would suggest that you take a stab at converting it, actually follow the tutorial to understand why things are what they are.
It's like someone putting gold out for anyone to take it, but you don't want it because it's square, not rectangular.
Answer by azmat786n · Dec 04, 2012 at 05:22 PM
//object prefab for clone
public var platform : GameObject;
//take this object into Camera you can do it (Drag this object drap onto Camera.
//object for spawn object
public var spawnPosition : Transform;
//one more position where platform going to destroye.
//also take this object in main Camera to
public var destroyPosition: Transform;
//set distance for next spawn
public var spawnDistance : float;
//this is automatic access do not change
private var lastPlatform : GameObject;
function Start() {
//Instantiate on start
lastPlatform = Instantiate(platform, spawnPosition.position, Quaternion.identity) as GameObject;
}
function Update() {
//make distance between 2 platforms
if (lastPlatform.transform.position.y + spawnDistance < spawnPosition.position.y)
{
//call one more function to getrate platforms
InstantiatePlatform();
}
//destroye if platform position lower then screen height
if(lastPlatform.transform.position.y < destroyPosition.position.y) {
//Destroy object
Destroy(lastPlatform);
}
}
function InstantiatePlatform()
{
lastPlatform = Instantiate(platform,new Vector3(Random.Range(-13,13) * 0.2f,spawnPosition.position.y,1),Quaternion.identity) as GameObject;
}
if you want this like runner you have to change some thing in above script like y position to go on x position move your spawnPosition game object onto x position ... but not difficult you can change.
this is for jumping game script platform generator where character jumping.
hope this is helpful to you