Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 TreeCat121 · Sep 21, 2020 at 10:08 PM · generationendless

How To Endlessly Make Land in a 2D Topdown game

I have been looking for 8 hours to try find a way to endlessly generate chunks and nothing. Plz can someone help me find something that will help me.

Edit: I have a generation script but generating Diagonally doesn't work can anyone help.

Here is my code:

using System.Collections; using System.Collections.Generic; using UnityEngine;

 public class Terrain : MonoBehaviour
 {
     public GameObject Chunk;
     public Transform Player;
     public int ChunkSize;
     public int Chunks;
     [SerializeField]List<Vector2> PreChunkedSpots = new List<Vector2>();
     List<GameObject> ChunksG = new List<GameObject>();
     public float UnloadDistance;
     public float ChunkUnder;
     void Start()
     {        
         ChunkCreate();
     }
     private void Update()
     {
         Vector2 MyPos = transform.position;
         Vector2 PlayerPos = Player.position;
         if (PlayerPos.x >= MyPos.x + (ChunkSize * ((Chunks / 2) - ChunkUnder)))
         {
             Vector2 PutPos = new Vector2(MyPos.x + (ChunkSize * Chunks), transform.position.y);
             transform.position = PutPos;
         }
         else if (PlayerPos.x <= MyPos.x - (ChunkSize * ((Chunks / 2) - ChunkUnder)))
         {
             Vector2 PutPos = new Vector2(MyPos.x - (ChunkSize * Chunks), transform.position.y);
             transform.position = PutPos;
         }
         if (PlayerPos.y >= MyPos.y + (ChunkSize * ((Chunks / 2) - ChunkUnder)))
         {
             Vector2 PutPos = new Vector2(transform.position.x, MyPos.y + (ChunkSize * Chunks));
             transform.position = PutPos;
         }
         else if (PlayerPos.y <= MyPos.y - (ChunkSize * ((Chunks / 2) - ChunkUnder)))
         {
             Vector2 PutPos = new Vector2(transform.position.x, MyPos.y - (ChunkSize * Chunks));
             transform.position = PutPos;
         }
 
         for (int i = 0; i < ChunksG.Count; i++)
         {
             if (Vector2.Distance(ChunksG[i].transform.position, Player.position) >= UnloadDistance)
             {
                 ChunksG[i].SetActive(false);
             }
             else
             {
                 ChunksG[i].SetActive(true);
             }
         }
         bool Spawn = true;
         for (int i = 0; i < PreChunkedSpots.Count; i++)
         {
             Vector2 PlayerPoss = transform.position;
             if (PlayerPoss == PreChunkedSpots[i])
             {
                 Spawn = false;
                 break;
             }
         }
         if (Spawn)
         {
             ChunkCreate();
         }
     }
     public void ChunkCreate()
     {
         for (int x = 0; x < Chunks; x++)
         {
             for (int y = 0; y < Chunks; y++)
             {
                 GameObject Inst = Instantiate(Chunk, new Vector2(transform.position.x + (((Chunks / 2) - x) * ChunkSize), transform.position.y + (((Chunks / 2) - y) * ChunkSize)), Quaternion.identity);
                 Inst.GetComponent<Chunk>().ChunkSize = ChunkSize;
                 ChunksG.Add(Inst);
             }
         }
         PreChunkedSpots.Add(transform.position);
     }
 }


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
0

Answer by streeetwalker · Sep 20, 2020 at 02:48 PM

There several tutorials that show you how to do this. Google "unity endless repeating background" or some variation thereof.

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 BranchOffGameStudio · Sep 20, 2020 at 03:22 PM

There's no one correct way to do this. I've written an asset called Isometric World Builder that I will be releasing in the near future that generates endless topdown procedural landmasses. If you want to start learning some basics of procedural generation I suggest this video series by Sebastian Lague. At the point where he starts using marching squares to generate 3D meshes is the point where you take the data and use it to generate a 2D map. I would suggest you look at the new Unity Tile system as you can easily place different tiles with rules to help give your generated world some polish. Here is a link to a video of the asset I've been working on. Hope this helps!

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

137 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 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

Rendering only when player is nearby. 1 Answer

How to create an endless track? 1 Answer

Making an endless tunnel 2 Answers

how one would go about using Triangulator in javascript? 0 Answers

Procedural terrain generation ? 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