Godot Version
4.2
Question
Hi,
I want to spawn a CharacterBody2D at a certain position. However it seems to be offset for some reason.
Here is the overall level. I added a ColorRect to the Marker2d to make it more visible.
Here is the code for the spawning logic
extends Marker2D
const WORKER = preload("res://worker.tscn")
func _on_timer_timeout() -> void:
var new_worker = WORKER.instantiate()
new_worker.global_position = global_position
add_child(new_worker)
Wondering what obvious thing I am getting wrong 
EX74
2
new_worker.position = global_position
Seems to still be the same issue. Added some print statements
var new_worker = WORKER.instantiate()
print("global_position" + str(global_position))
print("position" + str(position))
new_worker.position = global_position
add_child(new_worker)
And the output
global_position(990, 497)
position(990, 497)
So both are the same
EX74
4
do not instantiate the worker in Marked2D, but query the Marked2D position and then instantiate the worker
1 Like
Cheers, works now when I moved the logic to the level
extends Node2D
const WORKER = preload("res://worker.tscn")
@onready var worker_spawner: Marker2D = %WorkerSpawner
func _on_spawner_spawn_scene() -> void:
var new_worker = WORKER.instantiate()
new_worker.global_position = worker_spawner.global_position
add_child(new_worker)
Why is this different though?
1 Like
system
Closed
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.