Quantcast
Channel: Questions in topic: "endless"
Viewing all articles
Browse latest Browse all 123

How To Endlessly Make Land in a 2D Topdown game

$
0
0
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 PreChunkedSpots = new List(); List ChunksG = new List(); 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().ChunkSize = ChunkSize; ChunksG.Add(Inst); } } PreChunkedSpots.Add(transform.position); } }

Viewing all articles
Browse latest Browse all 123

Trending Articles