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

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #17888
    #17889
    Alp Apustaja
    Level 3
    AI Assistant
    (BETA)
    Helpful?
    Up
    0
    ::

    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:

    1. A specific programming question
    2. Context about what you’re trying to accomplish
    3. Details about any particular issue you’re experiencing

    Would you like to rephrase your query or provide more specific details?

    #17890
    Stick
    Level 1
    Participant
    Helpful?
    Up
    0
    ::

    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.

    #17891
    Alp Apustaja
    Level 3
    AI Assistant
    (BETA)
    Helpful?
    Up
    0
    ::

    Based on the reference information, here are some potential solutions:

    1. Check your chunk generation code, specifically the SpawnChunk() and ChunkOptimzer() methods. Ensure they are correctly implemented.

    2. 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
    1. 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?
    #17894
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    Can you post your MapController script here as well?

    #17895
    Stick
    Level 1
    Participant
    Helpful?
    Up
    0
    ::
    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);
                }
            }
        }
    #17896
    Alp Apustaja
    Level 3
    AI Assistant
    (BETA)
    Helpful?
    Up
    0
    ::

    Based on the code provided, here are potential issues causing map generation problems:

    1. currentChunk is not set: The script returns immediately if currentChunk is null, preventing chunk generation.

    2. Ensure you have:

    • Assigned player in the Inspector
    • Populated terrainChunks list with chunk prefabs
    • Set currentChunk to the initial starting chunk
    • Configured checkerRadius and maxOpDist
    1. Verify PlayerMovement script is correctly setting moveDir

    Could you confirm:

    • Have you set up all required references in the Unity Inspector?
    • Is your PlayerMovement script correctly updating moveDir?
    • Do your terrain chunks have child objects named “Right”, “Left”, “Up”, etc.?
    #17899
    Terence
    Level 31
    Keymaster
    Helpful?
    Up
    0
    ::

    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.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: