in this video, https://youtu.be/klBvssJE5Qg I shows you how to spawn enemies outside of a fixed camera. (this is in GDscript by the way) How could I make this work with a moving camera? I wanna make a zombie fighting game with a moving camera and zombies spawning outside that. I would really appreciate help with this.
I've tried researching on the internet about how to do it, but I just didn't find it.
N/A..................................
After looking at the video, I see they are using this line to spawn:
This suggest to me a couple thing:
self
passed as argument or global.And the answer is in another
castlevideo.In the video Godot Wave Shooter Tutorial #2 - Player Shooting we find this code:
And thus, we are working with global coordinates
global_position
. Thusenemy_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 theCamera2D
(or a child of it). Which means you need a reference to theCamera2D
(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 theCamera2D
using aRemoteTransform2D
. Either way, you could then work in its local coordinates. Thus you would do this:Or you could have a reference by exporting a
NodePath
(or in the newest Godot you can export aCamera2D
) from your script and set it via the inspector. So you can do this:Where
camera
is your reference to theCamera2D
.