Forum begins after the advertisement:
[Part 2] Problems with map generation. New map fragments are constantly appearing
Home › Forums › Video Game Tutorial Series › Creating a Rogue-like Shoot-em Up in Unity › [Part 2] Problems with map generation. New map fragments are constantly appearing
- This topic has 4 replies, 3 voices, and was last updated 1 week, 1 day ago by
Terence.
-
AuthorPosts
-
April 11, 2025 at 10:44 pm #17888April 11, 2025 at 10:50 pm #17889::
I apologize, but the query does not contain a specific question. The user has only provided some image links without any accompanying text or query. Could you please clarify what specific information or assistance you are seeking about these images or the Vampire Survivors tutorial series?
To help you effectively, I would need:
- A specific programming question
- Context about what you’re trying to accomplish
- Details about any particular issue you’re experiencing
Would you like to rephrase your query or provide more specific details?
April 11, 2025 at 10:53 pm #17890::I had a problem generating the map, I did everything as in the video, but nothing works. It just creates new objects all the time and doesn’t display them.
April 11, 2025 at 10:56 pm #17891::Based on the reference information, here are some potential solutions:
-
Check your chunk generation code, specifically the
SpawnChunk()
andChunkOptimzer()
methods. Ensure they are correctly implemented. -
Verify that your terrain chunks are properly set up:
- Create an empty GameObject named “Terrain Chunk”
- Reset its Transform
- Drag Background Grid as a child
- Create a “Props” child GameObject
- Create prop location points within the tilemap bounds
- Troubleshoot common tilemap issues:
- Check for gaps between tiles (ensure uniform tile sizing)
- Disable Anti-Aliasing in Project Settings > Quality
- Verify tile settings are consistent
Could you provide more specific details about:
- Your current chunk generation script
- How you’ve set up your terrain chunks
- Any specific error messages you’re seeing?
April 12, 2025 at 2:41 pm #17894April 12, 2025 at 7:22 pm #17895::public List<GameObject> terrainChunks; public GameObject player; public float checkerRadius; public Vector3 noTerrainPosition; public LayerMask terrainMask; public GameObject currentChunk; PlayerMovement pm; [Header("Optimization")] public List<GameObject> spawnedChunks; GameObject latestChunk; public float maxOpDist; float opDist; float optimizerCooldown; public float optimizerCooldownDur; void Start() { pm = FindObjectOfType<PlayerMovement>(); } void Update() { ChunkChecker(); ChunkOptimzer(); } void ChunkChecker() { if (!currentChunk) { return; } if (pm.moveDir.x > 0 && pm.moveDir.y == 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Right").position, checkerRadius, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Right").position; //Right SpawnChunk(); } } else if (pm.moveDir.x < 0 && pm.moveDir.y == 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Left").position, checkerRadius, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Left").position; //Left SpawnChunk(); } } else if (pm.moveDir.y > 0 && pm.moveDir.x == 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Up").position, checkerRadius, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Up").position; //Up SpawnChunk(); } } else if (pm.moveDir.y < 0 && pm.moveDir.x == 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Down").position, checkerRadius, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Down").position; //Down SpawnChunk(); } } else if (pm.moveDir.x > 0 && pm.moveDir.y > 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Right Up").position, checkerRadius, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Right Up").position; //Right up SpawnChunk(); } } else if (pm.moveDir.x > 0 && pm.moveDir.y < 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Right Down").position, checkerRadius, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Right Down").position; //Right down SpawnChunk(); } } else if (pm.moveDir.x < 0 && pm.moveDir.y > 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Left Up").position, checkerRadius, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Left Up").position; //Left up SpawnChunk(); } } else if (pm.moveDir.x < 0 && pm.moveDir.y < 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Left Down").position, checkerRadius, terrainMask)) { noTerrainPosition = currentChunk.transform.Find("Left Down").position; //Left down SpawnChunk(); } } } void SpawnChunk() { int rand = Random.Range(0, terrainChunks.Count); latestChunk = Instantiate(terrainChunks[rand], noTerrainPosition, Quaternion.identity); spawnedChunks.Add(latestChunk); } void ChunkOptimzer() { optimizerCooldown -= Time.deltaTime; if (optimizerCooldown <= 0f) { optimizerCooldown = optimizerCooldownDur; //Check every 1 second to save cost, change this value to lower to check more times } else { return; } foreach (GameObject chunk in spawnedChunks) { opDist = Vector3.Distance(player.transform.position, chunk.transform.position); if (opDist > maxOpDist) { chunk.SetActive(false); } else { chunk.SetActive(true); } } }
April 12, 2025 at 7:25 pm #17896::Based on the code provided, here are potential issues causing map generation problems:
-
currentChunk
is not set: The script returns immediately ifcurrentChunk
is null, preventing chunk generation. -
Ensure you have:
- Assigned
player
in the Inspector - Populated
terrainChunks
list with chunk prefabs - Set
currentChunk
to the initial starting chunk - Configured
checkerRadius
andmaxOpDist
- Verify
PlayerMovement
script is correctly settingmoveDir
Could you confirm:
- Have you set up all required references in the Unity Inspector?
- Is your
PlayerMovement
script correctly updatingmoveDir
? - Do your terrain chunks have child objects named “Right”, “Left”, “Up”, etc.?
April 13, 2025 at 2:32 pm #17899::Can you add the highlighted portions to your
ChunkChecker()
function, as shown below:void ChunkChecker() { if (!currentChunk) { return; } if (pm.moveDir.x > 0 && pm.moveDir.y == 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Right").position, checkerRadius, terrainMask)) { print("Spawning chunk on the right"); noTerrainPosition = currentChunk.transform.Find("Right").position; //Right SpawnChunk(); } } else if (pm.moveDir.x < 0 && pm.moveDir.y == 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Left").position, checkerRadius, terrainMask)) { print("Spawning chunk on the left"); noTerrainPosition = currentChunk.transform.Find("Left").position; //Left SpawnChunk(); } } else if (pm.moveDir.y > 0 && pm.moveDir.x == 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Up").position, checkerRadius, terrainMask)) { print("Spawning chunk upwards"); noTerrainPosition = currentChunk.transform.Find("Up").position; //Up SpawnChunk(); } } else if (pm.moveDir.y < 0 && pm.moveDir.x == 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Down").position, checkerRadius, terrainMask)) { print("Spawning chunk downwards"); noTerrainPosition = currentChunk.transform.Find("Down").position; //Down SpawnChunk(); } } else if (pm.moveDir.x > 0 && pm.moveDir.y > 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Right Up").position, checkerRadius, terrainMask)) { print("Spawning chunk on the right up"); noTerrainPosition = currentChunk.transform.Find("Right Up").position; //Right up SpawnChunk(); } } else if (pm.moveDir.x > 0 && pm.moveDir.y < 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Right Down").position, checkerRadius, terrainMask)) { print("Spawning chunk on the right down"); noTerrainPosition = currentChunk.transform.Find("Right Down").position; //Right down SpawnChunk(); } } else if (pm.moveDir.x < 0 && pm.moveDir.y > 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Left Up").position, checkerRadius, terrainMask)) { print("Spawning chunk on the left up"); noTerrainPosition = currentChunk.transform.Find("Left Up").position; //Left up SpawnChunk(); } } else if (pm.moveDir.x < 0 && pm.moveDir.y < 0) { if (!Physics2D.OverlapCircle(currentChunk.transform.Find("Left Down").position, checkerRadius, terrainMask)) { print("Spawning chunk on the left down"); noTerrainPosition = currentChunk.transform.Find("Left Down").position; //Left down SpawnChunk(); } } }
Then let me know the messages that show up when your game is running.
I suspect either your chunks are set up improperly, or the chunk checker GameObjects are set up such that they keep firing incorrectly.
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: