After looking at the video, I see they are using this line to spawn:
Global.instance_node(enemy_1, enemy_position, self)
This suggest to me a couple thing:
- The position is probably either relative to the
self
passed as argument or global.
- There must be an Autoload called Global that I need to check to make sure.
And the answer is in another castle video.
In the video Godot Wave Shooter Tutorial #2 - Player Shooting we find this code:
extends Node
func instance_node(node, location, parent):
var node_isntance = node.instance()
parent.add_child(node_instance)
node_instance.global_position = location
return node_instance
And thus, we are working with global coordinates global_position
. Thus enemy_position
is used as global coordinates.
Ok, instead of using enemy_position
as global coordinates we are going to use it as local coordinates of the Camera2D
(or a child of it). Which means you need a reference to the Camera2D
(which I don't know where do you have it).
You could make your code in a child of the Camera2D
, or take the transform of the Camera2D
using a RemoteTransform2D
. Either way, you could then work in its local coordinates. Thus you would do this:
Global.instance_node(enemy_1, to_global(enemy_position), self)
Or you could have a reference by exporting a NodePath
(or in the newest Godot you can export a Camera2D
) from your script and set it via the inspector. So you can do this:
Global.instance_node(enemy_1, camera.to_global(enemy_position), self)
Where camera
is your reference to the Camera2D
.