Godot Version
Godot 4.7.1
Question
I am struggling to get my buildings to turn correctly, I have them spawning in the right place but sometimes my roads and buildings rotate 180 degrees for seemingly no reason, I have tried a lot of stuff but I need another perspective on it, I’ll share my generation script and my street script
extends Node3D
const STREET_TEMPLATE1 = preload("res://Streets/street_template.tscn") # Road 1
const STREET_TEMPLATE2 = preload("res://Streets/street_template2.tscn") # Road 2
const BUILDING1 = preload("res://Streets/Building.tscn")
const crystal = preload("res://Collectibles/crystal.tscn")
const BOOST = preload("res://Collectibles/boost.tscn")
var roads_to_spawn: Array = [STREET_TEMPLATE1, STREET_TEMPLATE2, BUILDING1, BUILDING1, BUILDING1] # Possible roads to spawn
var collectibles_to_spawn: Array = [crystal, BOOST]
@onready var starting_street: street = $Roads/StreetTemplate # The starting street
@onready var roads: Node3D = $Roads # The node all roads are under
@onready var collectibles: Node3D = $Collectibles
var recently_summoned_collectibles: Array = []
var player
var collectible_spawned: bool = false
func _ready() -> void:
starting_street.entered.connect(enter, CONNECT_ONE_SHOT)
func enter(street_node: street):
for child in street_node.get_links(street_node.links):
var road = roads_to_spawn.pick_random()
var road_spawn = road.instantiate()
roads.add_child(road_spawn)
road_spawn.global_transform = child.global_transform
if not road_spawn.is_in_group("Building"):
road_spawn.entered.connect(disable, CONNECT_ONE_SHOT)
road_spawn.set_enter_potential(true)
for child in street_node.get_links(street_node.collectibles_links):
if not collectible_spawned and randi_range(1, 5) == 1:
collectible_spawned = true
var collectible_node = collectibles_to_spawn.pick_random()
var collectible_spawn = collectible_node.instantiate()
collectibles.add_child(collectible_spawn)
collectible_spawn.global_position = child.global_position
recently_summoned_collectibles.append(collectible_spawn)
if find_player():
player.connect_collectible(collectible_spawn)
collectible_spawned = false
func disable(not_disable: street):
not_disable.set_enter_potential(false)
for child in roads.get_children():
if child != not_disable:
child.queue_free()
for child in collectibles.get_children():
if child not in recently_summoned_collectibles:
child.queue_free()
await get_tree().process_frame
recently_summoned_collectibles.clear()
if is_instance_valid(not_disable):
enter(not_disable)
func find_player():
for child in get_tree().get_first_node_in_group("Player").get_children():
if child.name == "CharacterBody3D":
player = child
return true
return false
extends StaticBody3D
class_name street
var has_been_entered: bool = false
@onready var links: Node3D = $Links
@onready var collectibles_links: Node3D = $CollectiblesLinks
signal entered(node_to_keep: street)
@onready var area: Area3D = $Area3D
@export var starting_street_node: bool = false
var collectibles: Array = []
func _ready() -> void:
if starting_street_node:
area.monitoring = true
func find_link_loc(Link: Node3D):
for child in links.get_children():
if child == Link:
return child.global_transform
func get_links(link: Node3D):
return link.get_children()
func _on_area_3d_body_entered(body: Node3D) -> void:
if body.is_in_group("Player") and not has_been_entered:
has_been_entered = true
entered.emit(self)
func set_enter_potential(value: bool):
if not is_inside_tree():
return
area.set_deferred("monitoring", value)