i am trying to make a random 3d wall generation from a static block i set up
i have a simple gdscript to do this but i need it to connect to walls around it and make it less clippy as right now there is alot of overlaps with the walls and it's quite slow
i need help improving the code and making the generation alot better
if you could help me with the code or give me links to help me research on how to do it better that would be great, many thanks in advance
here is my code so far:
extends Node
onready var hall = preload("res://wall_stright.tscn")
onready var hal = preload("res://wall_left.tscn")
var y = 0.0
# var num = 100#
# var cords_x = []
# var cords_z = []
# var temp = -1
#if 1 == 1:
# var valid = false # valid loop so object's don't spawn inside each other#
# while not valid:
# var num_count = 0
# gen x and z cords
#x = randi() % num
#z = randi() % num
# check if space is already taken
#temp = cords_x.find(x)
#if temp == -1:
# for v in range(int(x-5), int(x+5)):
# temp = cords_x.find(v)
# if temp == -1:#
# num_count += 1
#
# temp = cords_z.find(z)
# if temp == -1 and num_count >= 5:
# cords_x.append(x)#
# cords_z.append(z)
# valid = true
func check_cords(cords, base):
var temp = -1
var count = 0
for i in range(int(base-2), int(base+2)):
print("i: ", i)
temp = cords.find(i)
if temp != -1:
count += 1
if count >= 5:
return true
else:
return false
func add_wall_right(float_x, float_z):
var hall_add = hall.instance()
add_child(hall_add)
# move to cords in scene
hall_add.transform.origin = Vector3(float_x, y, float_z)
func add_wall_left(float_x, float_z):
pass
func gen():
# all veriables used (will refine after make)
var x = 0
var x_cords = [] # this is so there is no close collison
var z = 0
var z_cords = [] # this is so there is no close collsion
var op = 0
var float_x = 0.00
var float_z = 0.00
var num = 100
var temp = bool()
var valid = false
for i in range(0, 10): # for loop to gen first bit of the map (this is the amont of walls to gen
print("adding object...")
valid = false
while not valid:
# print("oh oh")
x = randi() % num
z = randi() % num
print("pre data")
print("pre x: ", x)
print("pre z: ", z)
if x_cords.find(x) == -1:#
#temp = check_cords(x_cords, x)
# if temp == true:
valid=true
# else:
# valid=false
else:
valid=false
if z_cords.find(z) == -1:
#temp = check_cords(z_cords, z)
#if temp == true:
valid=true
# else:
# valid=false
else:
valid=false
x_cords.append(x)
z_cords.append(z)
op = randi() % 2
# convet to float
float_x = float(x) + 0.00
float_z = float(z) + 0.00
print("x: ", float_x)
print("z: ", float_z)
print("op: ", op)
# add to scene
if op == 1:
var hall_add = hall.instance()
add_child(hall_add)
# move to cords in scene
hall_add.transform.origin = Vector3(float_x, y, float_z)
# the code below just adds extends the walls
var cho = randi() % 5
for cell in range(0, 5):
float_z += 5
var hal_dd = hall.instance()
add_child(hal_dd)
# move to cords in scene
hal_dd.transform.origin = Vector3(float_x, y, float_z)
else:
var hall_add = hal.instance()
add_child(hall_add)
# move to cords in scene
hall_add.transform.origin = Vector3(float_x, y, float_z)
# the code below just adds extends the walls
var cho = randi() % 5
for cell in range(0, 5):
op = randi() % 2
float_x += 10
var hal_dd = hal.instance()
add_child(hal_dd)
# move to cords in scene
hal_dd.transform.origin = Vector3(float_x, y, float_z)
func _ready():
print("runing...")
randomize()
gen()
#for i in range(0, 100):
# pass