#Random Level Gen not working

1 messages · Page 1 of 1 (latest)

tall meadow
#

I'm trying to continuously generate new parts of a side scroller and in those new parts, I want to generate 2 lines of walls that have only a chance of generating. The bugs currently are the level not generating past the second chunk(first generated chunk) and the walls after my beginning chunk not generating in the right place

#

I won't be able to respond for about 4 hours and possibly 2 hours after that

fair cargo
#

@tall meadow When you are ready can you send a video of it in action and some pics of the code?

tall meadow
#

wall generation

#

chunk generation

#

as said before the two problems are

  1. chunks after the second one(but I think its the first generated chunk as the first one is just placed in the game) don't generate.

  2. walls after the first chunk do not generate.

I believe these two problems are connected and due to the first chunk being placed rather than generated

#

Also random thing I checked, even if I get rid of the first chunk, walls in the first chunk still generate

fair cargo
#

What does "ChunkCheck" Check? @tall meadow

tall meadow
#

I believe I made it to check through all currently generated chunk positions and if the possible chunk was not in this list it would generate

#

I did this to prevent chunk generating constantly on the same position

tall meadow
#

@fair cargo

fair cargo
#

So do all chunks that should be spawned spawn when you spawn in but when you go outside of the players "render distance" they stop spawning?

#

@tall meadow

fair cargo
#

And may i also se the rest of the code?

fair cargo
#

@tall meadow

tall meadow
#

bottom right is a different script from the other 3, which are all apart of the same one @fair cargo

fair cargo
# tall meadow

Is there any code above what is shown here and if so may i see it?

tall meadow
#

Nothing else for this project

#

@fair cargo

fair cargo
#

I was wondering because the code starts at line 13

#

Are there any variables up there?

#

@tall meadow

tall meadow
#

For which one?

fair cargo
#

For the chunk gen one

fair cargo
tall meadow
#

heres the other part of that

tall meadow
#

@fair cargo

fair cargo
#

Have you found the solution?

tall meadow
#

no

tall meadow
#

@fair cargo

fair cargo
#

This was a tricky instance to say at least

#

Tomorrow i will take a pen and paper and try to figure it out once and for all

tall meadow
#

ty

fair cargo
#
# fix chunks not generating infinitely
# fix position of walls (should be lower)
func _process(delta):
    var chunkCheck = true
    var playerGame = get_node("Player")
    var player_posX = playerGame.global_position.x
    var player_posX = int(player_posX)
    
    var chunkPossiblePosX = floor(player_posX / 1000.0) * 1000
    var tankGame = get_node("Tank")
    var tank_posX = tankGame.global_position.x

    for i in chunkList:
        if chunkPossiblePosX == i.x:
            chunkCheck = false
    if chunkCheck == true:
        print(true)
        var chunk = levelScene.instantiate()
        add_child(chunk)
        chunk.global_position = Vector2(chunkPossiblePosX, -100)
        chunkList.append(chunk.global_position)


Try this code

#

It should (Or rather i hope it will) work

#

But we need to see it in action first!

#

@tall meadow

tall meadow
#

yup it works

#

I had to change two parts of the code as one caused an error(var player_posX = int(player_posX)) and the walls were slightly off so I had to move them down but otherwise everything works

#

thank you!

#

@fair cargo

fair cargo
tall meadow
#

hey how do you remove something from a list?

#

pop?

#

nvm

fair cargo
#

Yea i believe that it is pop

#

Although there are a few different ways to do it

tall meadow
#

its erase in godot