Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by TastyTurban · Aug 07, 2016 at 01:24 PM · instantiate3dnoobendless runnerstatic vars

"Infinite" terrain algorithm for 3D endless runner?

Hi guys, i've been following some tutorials online and am trying to expand on a basic 3D endless runner and remove the bounds of the left and right wall; so the character can move freely on the X axis.

My code is kind of working, the issue is that the floor tile that is instantiated is given a gameObject name of currentTile, and when the character moves left or right, the called left or right tile is spawned, but when the player enters into the next forward tile spawn trigger, it still generates on the original forward path.

Sorry its kind of hard to explain, but the code works fine for doing a basic endless runner, with tiles spawning only in front of the character. I think what i need to do is have some kind of a static gameObject as the next spawned floor tile, but I can't figure out what to do next.

Here's the current code for TileManaging:

 public class TileManager : MonoBehaviour
 {
     public GameObject forwardTilePrefab;
     public GameObject leftTilePrefab;
     public GameObject rightTilePrefab;
 
     public GameObject currentTile;
 
     public Collider forwardCollisionZone;
     public Collider leftCollisionZone;
     public Collider rightCollisionZone;
 
     private static TileManager instance;
 
     public static TileManager Instance
     {
         get
         {
             if (instance == null)
             {
                 instance = FindObjectOfType<TileManager>();
             }
             { return instance; }
         }
     }
 
      public void SpawnForward()
     {
         currentTile = (GameObject)Instantiate(forwardTilePrefab, currentTile.transform.GetChild(0).GetChild(0).transform.GetChild(0).position, Quaternion.identity);
         currentTile.gameObject.tag = "FWtile";
     }
 
     public void SpawnLeft()
     {
         Instantiate(forwardTilePrefab, currentTile.transform.GetChild(0).GetChild(0).GetChild(1).transform.position, Quaternion.identity);
         currentTile.gameObject.tag = "LFtile";
     }
 
     public void SpawnRight()
     {
         if (LeftTileSpawner.leftJustUsed == false)
         {
             Instantiate(forwardTilePrefab, currentTile.transform.GetChild(0).GetChild(0).GetChild(2).transform.position, Quaternion.identity);
             currentTile.gameObject.tag = "RTtile";
         }
         else return;
     }
 }

And for the colliders/triggers:

 public class RightTileSpawner : MonoBehaviour
 {
     public Collider RightColBox;
     public bool wasUsed;
 
     public void OnTriggerEnter(Collider name)
     {
         if (name.tag == "Player")
         {
             print("Right Collider hit");
             wasUsed = true;
             TileManager.Instance.SpawnRight();
        
         }
     }
 }

The tag doesn't get updated in the game either, but that's not really a concern right now.

Thank you so much for reading all that, if you can come up with anything please let me know!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by fahimalavi · Aug 07, 2016 at 02:44 PM

Usually in endless runner game, character stands at its position (0,0,0) only world moves except of jumps.

You can mimic infinite X axis movement by

1) Making terrain blocks reasonably big in x-Axis such that a player won't able to pass through in x-axis until terrain passed back. 2) When player moves in X-Axis, shift all terrain blocks in x-axis. 3) keep creating new terrains at 0,0,Z. ()

There could be dozens of ways but if I would be you then would do like it

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by TastyTurban · Aug 08, 2016 at 05:09 AM

Thank you fahi, I hadn't thought of making the player static! I would still like to see if i could fix the terrain spawner though, but if cannot that seems like a good way to go about it!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

80 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Singleton / DontDestroyOnLoad / Instantiation referencing 0 Answers

Collisions only working in the editor but not in the build 0 Answers

how do I duplicate an object and have it be in a different position? 2 Answers

Why wont my object Instantiate? 0 Answers

problems with instantiating a moving prefab. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges