Tree collisions and highlights

This commit is contained in:
Dan Baker 2025-06-26 18:28:33 +01:00
parent 57602adddb
commit 7255cbdf64
17 changed files with 231 additions and 2251 deletions

View file

@ -11,29 +11,14 @@ func _ready():
func spawn_trees_for_cell(cell_info: CellDataResource):
if not cell_info:
return
# Use parent's RNG instead of creating new one
if not parent_ground_tile or not parent_ground_tile.rng:
return
return
if not parent_ground_tile:
return
var tree_count = max(0, cell_info.trees.size())
spawn_trees(tree_count)
# Update all rng calls to use parent_ground_tile.rng:
func get_random_position() -> Vector3:
var x = parent_ground_tile.rng.randf_range(-spawn_area_size.x / 2, spawn_area_size.x / 2)
var z = parent_ground_tile.rng.randf_range(-spawn_area_size.y / 2, spawn_area_size.y / 2)
return Vector3(x, 0, z)
func spawn_tree_at_position(pos: Vector3):
var random_index = parent_ground_tile.rng.randi() % tree_scenes.size()
var random_tree_scene = tree_scenes[random_index]
var tree_instance = random_tree_scene.instantiate()
add_child(tree_instance)
tree_instance.position = pos
tree_instance.rotation.y = parent_ground_tile.rng.randf() * TAU
func spawn_trees(tree_count: int):
if tree_scenes.is_empty() or tree_count == 0:
return
@ -56,6 +41,21 @@ func spawn_trees(tree_count: int):
attempts += 1
func get_random_position() -> Vector3:
var rng = parent_ground_tile.get_rng()
var x = rng.randf_range(-spawn_area_size.x / 2, spawn_area_size.x / 2)
var z = rng.randf_range(-spawn_area_size.y / 2, spawn_area_size.y / 2)
return Vector3(x, 0, z)
func spawn_tree_at_position(pos: Vector3):
var rng = parent_ground_tile.get_rng()
var random_index = rng.randi() % tree_scenes.size()
var random_tree_scene = tree_scenes[random_index]
var tree_instance = random_tree_scene.instantiate()
add_child(tree_instance)
tree_instance.position = pos
tree_instance.rotation.y = rng.randf() * TAU
func is_position_valid(pos: Vector3) -> bool:
for existing_pos in spawned_positions:
if pos.distance_to(existing_pos) < min_distance: