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 /
avatar image
0
Question by stfx · Jul 05, 2011 at 08:51 PM · terrainseamlessterrain seamless

Programming techniques: Long rail type levels (seamless terrain)

I am currently thinking about the best way to load the terrain of a rail type shooter. Obviously placing all the terrain elements in the Editor is not the best approach.

I was thinking about generating new instances of terrain as we get close to the end of the current one.

 public GameObject TerrainPrefab;
 void AddTerrain(Vector3 pos)
 {
     GameObject fire = (GameObject)Instantiate(TerrainPrefab, pos, Quaternion.identity);
 }

But that causes small fps drops which might not be noticeable if you have an almost empty scene but it might cause lag spikes in the final game where every bit of performance important. Making it asynchronous would work but I dont know if thats even possible with Unity.

Second approach I could think of is only having 2 instances of terrain and after passing the previous one it gets moved after the current one and the new terrain gets loaded into the terrain data. But then again I am not sure if swapping the terrain data would essentially require the same amount of calculation as the first approach.

EDIT: Now I saw that Unity has a LoadLevelAdditivieAsync function but that is for the PRO version only which I cant afford yet. Actually I only need to load the terrain asynchronous.

I am fairly new to Unity and also in general to game development so I would like to get some opinions from experienced people.

What do you think? What might be the best approach? Is it possible to do it asynchronous in a new thread or something like that in Unity Free to counter lag spikes?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by save · Jul 06, 2011 at 08:27 AM

Have a look at this free Infinite Terrain project. There's also the possibility to just move the player and its comforting space and relocating at the very origin point when the track runs out (instead of moving everything else, which is far more intense).

Unity runs all coroutines in a single thread where some features, already defined by the engine, is multi-threaded. You cannot tell Unity what to multi-thread. Although not to confuse with multitasking, which Unity is great at. For future versions of Unity (with v3.3 as current) more things will be capable of multi-threading. Version 3.5 will have a multi-threaded renderer for instance - which will take some load off of everything else.

Here's some more information about infinite/seamless terrains:

http://answers.unity3d.com/questions/9633/possible-infinite-terrain-plane.html

http://answers.unity3d.com/questions/17225/dynamic-terrain-loading.html

Comment
Add comment · Show 3 · 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 stfx · Jul 06, 2011 at 11:20 AM 0
Share

Thanks for your answer. Though I still have a few questions:

  1. Do you mean like relocating every seen object to the origin?

  2. Does that mean that it is not possible to load terrain async without Unity pro? And moving terrain and stuff like that is never done in the background no matter what?

  3. How far can we go into one direction, not relocating to the origin, without causing problems? 100.000 meters? more/less?

avatar image stfx · Jul 06, 2011 at 12:00 PM 0
Share

Also I came across StartCoroutine and wrote the following code. What do you think? is it necessary to yield return on every line? Is it slow to check for terrainData != TerrainData and only then assign it?

 IEnumerator $$anonymous$$oveTerrain()
 {
     if (TerrainA.terrainData != TerrainData[terrainIndex])
         TerrainA.terrainData = TerrainData[terrainIndex];

     yield return new WaitForSeconds(1);
     SetTerrainNeighbors(TerrainB, TerrainA);
     yield return new WaitForSeconds(1);
     TerrainA.transform.position = TerrainB.transform.position + new Vector3(0, 0, 2000);
 }
avatar image save · Jul 06, 2011 at 12:10 PM 0
Share

1 & 3: At some point you'll have to relocate the player as Unity starts getting physic artifacts at ~20k units away from the world origin (0,0,0). This is due to the single-precision floating point that Unity uses to locate and position objects.

You can use logic where you move everything around the player for really massive scenes, instantiate objects in front of the player and remove them behind the player, above camera culling distances.

The best implementation differs quite vastly depending on the situation for your games behavior.

2: You shouldn't have to load levels additive if you just want to create a seamless world - but it all depends on what your game and structure demands.

Hopefully someone else can fill you in a bit further if you're able to give a bit more detail about how the logic should work in your game:

Is it 3d/2d?

Is it a one-way track?

Is the player always moving with an object or can it get off, similar to a train-ride?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

repeating textures (how to solve it) 3 Answers

Make a simple tree 1 Answer

Terrains are not as seamless as their heightmaps. 0 Answers

Help with using this code for seamless terain PleaseHelp I realy need it. 1 Answer

Terrain size and 16 bit heightmaps 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