- Home /
Generate players path on the Fly
"I have different junctions i.e turn right, turn left etc. i want to connect these junctions randomly on the fly. so that the user have an illusion of endless running track. Secondly the player(with Third person camera) is just animating like its running but actually its not, rather the junctions are moving towards the player. I am new to Unity and Game Development. Please advice me the best possible approach to achieve this. Its more like Temple Run i hope you guys know about it."
Updating Since i get no help so i started it. I have started creating the Junctions recursively at 0,0,0 also applying translation to z-axis of the junction by 0.01f. As soon as this junction reaches 0,0,2.3. i call in for the new Junction and place it at 0,0,0.
The problem is i see a flickering line between the two junctions, Also the transition is not smooth enough for the illusion that the player is running.
I appreciate if some body can help.
Code below is applied on Junctions i.e Tiles
public class Translation : MonoBehaviour {
// Use this for initialization void Start () {
}
// Update is called once per frame void Update () { transform.Translate(new Vector3(0f,0f,0.01f)); } }
Below is the code applied to an emptyGame object as GameManager
public class TileHandler : MonoBehaviour {
// Use this for initialization static GameObject objTile; static Vector3 spawnPosition=new Vector3(0f,0f,0f); // Tile's Spawn Position static Queue stkGameobject=new Queue(); Vector3 previousTilePosition; void Start() { ChangeTile(); } public void ChangeTile() { // Get a new Random Junction Tile t= TileGenerator.GetTile(); objTile=Instantiate(t.TileObject, spawnPosition, Quaternion.identity) as GameObject; // Destroying un needed Junctions that have passed the player. stkGameobject.Enqueue(objTile.gameObject); if (stkGameobject.Count>3) { Destroy(stkGameobject.Dequeue()); } } void Update() { //Create New Tile When the previous tile reach this position Vector3 v3=new Vector3(0.0f,0.0f,2.3f); if (objTile.transform.position == v3) { ChangeTile(); } } }
Please do share if you guys have any better idea to do it.
Answer by kashiftasneem · Feb 25, 2013 at 05:54 AM
What i feel is in temple run is a static environment with various turns which always end up in that environment. You cant create new junctions at every turn as it will be very memory consuming. You can do is that place random small objects on turns which gives the effect of new turn. For the player movement, create an empty game object with two children camera and player object. player object will be a collider and a rigid body. It will have one child which will be player running animation object. Apply force to rigid body to move the player
Your answer
Follow this Question
Related Questions
Creating a mesh and assigning a material during edit time. 1 Answer
Generate random path in grid 1 Answer
Best way to dynamically generate textures? 0 Answers
iTween change orienttopath mid path? 0 Answers
Resources.Load dynamic path 2 Answers