proper handling of nesting in coordinates

This commit is contained in:
2024-08-02 04:38:05 +03:00
parent 59384ce345
commit 8908b51103
5 changed files with 41 additions and 20 deletions

View File

@ -22,8 +22,13 @@ func generate_geometry() -> Node3D:
func get_spawn_point() -> Vector3:
for child in get_children():
if child is SpaceSpawn:
return child.space_position(self)
var stack := [self]
while stack:
var node = stack.pop_front()
for child in node.get_children():
if child is SpaceSpawn:
return child.space_position(self)
stack.push_back(child)
return Vector3.ZERO

View File

@ -1,7 +1,10 @@
@tool
extends SpaceEntity
class_name SpaceRegion
## Classic 2.5D sector beauty.
##
class_name SpaceRegion
@export var elevation: float = 0.0
@export var height: float = 100.0
@ -13,9 +16,19 @@ func generate_geometry(space: Space) -> Node3D:
return _generate_geometry(space, true)
func _process(delta):
if Engine.is_editor_hint():
self.texture = floor_texture
func _generate_geometry(space: Space, looked_from_inside: bool) -> Node3D:
var geometry := MeshInstance3D.new()
geometry.name = name
geometry.position = Vector3(
position.x * space.unit_scale,
0,
position.y * space.unit_scale,
)
var mesh := ArrayMesh.new()
mesh.add_surface_from_arrays(Mesh.PRIMITIVE_TRIANGLES, _generate_wall_arrays(space, looked_from_inside))

View File

@ -7,4 +7,4 @@ class_name SpaceSpawn
func space_position(space: Space) -> Vector3:
# todo: Get current region elevation
return Vector3(position.x * space.unit_scale, 0, position.y * space.unit_scale)
return Vector3(global_position.x * space.unit_scale, 0, global_position.y * space.unit_scale)