4.4
I’m trying to setup procedural generation for my game, and I am clueless so I followed a tutorial and figured I could mess with it until it works, but I’m getting a Invalid operands ‘Callable’ and ‘float’ in operator ‘<=’ error and I have no clue what I’m doing, Anyway here’s my code.
Blockquote
extends Node
const GENERATION_BOUND_DISTANCE = 8
var player
var noise
func _ready() → void:
noise = FastNoiseLite.new()
player = $“…/Player”
generate_new_cubes_from_position(player.position)
func _process(_delta: float) → void:
pass
func get_color_from_noise(noise_value):
if noise_value <= -.4:
return Color(1,0,0,1)
elif noise_value <= -.2:
return Color(0,1,0,1)
elif noise_value <= 0:
return Color(0,0,1,1)
elif noise_value <= .2:
return Color(.5,.5,.5,1)
elif noise_value > .2:
return Color(.3,.8,.5,1)
func create_cube(position, color):
var box_size = Vector3(1,1,1)
var static_body = StaticBody3D.new()
var collision_shape_3d = CollisionShape3D.new()
collision_shape_3d.position = position
collision_shape_3d.shape = BoxShape3D.new()
collision_shape_3d.shape.size = box_size
var mesh = MeshInstance3D.new()
var boxmesh = BoxMesh.new()
boxmesh.size = box_size
var material = StandardMaterial3D.new()
material.albedo_color = color
boxmesh.material = material
mesh.set_mesh(boxmesh)
mesh.set_position(position)
static_body.add_child(mesh)
static_body.add_child(collision_shape_3d)
add_child(static_body)
func generate_new_cubes_from_position(player_position):
for x in range(GENERATION_BOUND_DISTANCE*2):
x += (player_position.x - GENERATION_BOUND_DISTANCE)
for z in range(GENERATION_BOUND_DISTANCE):
z += (player_position.x - GENERATION_BOUND_DISTANCE)
generate_cube_if_new(x,z)
func generate_cube_if_new(x,z):
create_cube(Vector3(x,0,z), get_color_from_noise(noise.get_noise_2d))