Godot Version
4.6.3
Question
Fair warning: I’m pretty new to Godot, so there’s a non-zero chance I’ve messed up something basic.
I’m trying to attached two tiles (instantiated scenes) together by aligning their markers.
To do this, one of the steps is to calculate the offset from that marker to the centre of the scene.
However, I’m running into issues with this, because the marker is always reporting it’s position as 0,0,0, even if I move the parent scene.
func attach_tile(new_tile: Node3D, attach_point: Marker3D) -> void:
await get_tree().process_frame # Here just in case it matters. I'll remove it if i can and it still works.
var marker: Marker3D = new_tile.get_tree().get_first_node_in_group("AttachMarker")
var marker_offset = marker.global_position - new_tile.global_position
print("START")
print(marker.global_position)
print(new_tile.global_position)
#print(marker_offset)
#print(attach_point.global_position)
new_tile.global_position = attach_point.global_position - marker_offset
Outputs the following:
START
(0.0, -0.0, 0.0)
(0.0, 0.0, 0.0)
Modifying the code to move the tile first:
func attach_tile(new_tile: Node3D, attach_point: Marker3D) -> void:
await get_tree().process_frame # Here just in case it matters. I'll remove it if i can and it still works.
new_tile.global_position += Vector3.UP*50*PI
var marker: Marker3D = new_tile.get_tree().get_first_node_in_group("AttachMarker")
var marker_offset = marker.global_position - new_tile.global_position
print("START")
print(marker.global_position)
print(new_tile.global_position)
#print(marker_offset)
#print(attach_point.global_position)
new_tile.global_position = attach_point.global_position - marker_offset
Has no effect on the reported marker position
Output:
START
(0.0, -0.0, 0.0)
(0.0, 157.0796, 0.0)
This tile is an inherited scene, inheriting from a blender import. These markers were attached at attachment points.
The markers have visibly different positions from the root node in the 3d viewer.
I’m genuinely stumped at this one. Here’s a larger snapshot of code, if it helps.
level() is called in _ready(), and GameState is a global variable bank.
func attach_tile(new_tile: Node3D, attach_point: Marker3D) -> void:
await get_tree().process_frame # Here just in case it matters. I'll remove it if i can and it still works.
var marker: Marker3D = new_tile.get_tree().get_first_node_in_group("AttachMarker")
var marker_offset = marker.global_position - new_tile.global_position
print("START")
print(marker.global_position)
print(new_tile.global_position)
#print(marker_offset)
#print(attach_point.global_position)
new_tile.global_position = attach_point.global_position - marker_offset
# To return bool and number when fully implemented, not yet complete.
func level():
if is_multiplayer_authority():
GameState.reset_levelstate.rpc()
GameState.reset_generationstate()
var generate_tile = func() -> Dictionary:
var new_tile := TEMP.instantiate()
#new_tile.top_level = true
new_tile.scale = Vector3.ONE * (1.0/3.0)
add_child(new_tile)
var tree := new_tile.get_tree()
var nodes := tree.get_nodes_in_group("Nodes")
var ground_spawns := tree.get_nodes_in_group("GroundSpawns")
var air_spawns := tree.get_nodes_in_group("AirSpawns")
var chosen_node_id := randi() % nodes.size()
var exit_nodes = nodes.duplicate()
exit_nodes.remove_at(chosen_node_id)
var chosen_exit_node_id := randi() % exit_nodes.size()
var chosen_node: Marker3D = nodes[chosen_node_id]
var chosen_exit_node: Marker3D = exit_nodes[chosen_exit_node_id]
assert(chosen_node != chosen_exit_node, "Node and Exit node are the same!")
# Label marker, for attaching.
chosen_node.add_to_group("AttachMarker")
# Flip exit marker, so it can attach to other pieces properly.
chosen_exit_node.rotate_object_local(Vector3.UP, PI)
var anchor_pos = GameState.generationState["AnchorPos"]
var anchor_dir = GameState.generationState["AnchorDir"]
chosen_node.global_position = anchor_pos
chosen_node.look_at(global_position + anchor_dir)
if GameState.generationState["AnchorMarker"]:
attach_tile(new_tile, GameState.generationState["AnchorMarker"])
GameState.generationState["AnchorPos"] = chosen_exit_node.position
GameState.generationState["AnchorDir"] = -chosen_exit_node.global_transform.basis.z
GameState.generationState["AnchorMarker"] = chosen_exit_node
return {
"tile": new_tile,
"exit_pos": chosen_exit_node.position,
"exit_dir": -chosen_exit_node.global_transform.basis.z
}
for i in range(2):
var tile_data = await generate_tile.call()









