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
#Random Level Gen not working
1 messages · Page 1 of 1 (latest)
@tall meadow When you are ready can you send a video of it in action and some pics of the code?
wall generation
chunk generation
as said before the two problems are
-
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.
-
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
What does "ChunkCheck" Check? @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
@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
And may i also se the rest of the code?
@tall meadow
Yes, that is the bug
sure, I only have 2 other scripts but they should be causing any problems
bottom right is a different script from the other 3, which are all apart of the same one @fair cargo
Is there any code above what is shown here and if so may i see it?
I was wondering because the code starts at line 13
Are there any variables up there?
@tall meadow
For which one?
For the chunk gen one
This one
heres the other part of that
@fair cargo
Have you found the solution?
no
@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
ty
# 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
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
No problem friend! If you ever have a problem feel free to DM me and i will do my best to help :)
its erase in godot