|
|
|
 |
Reply From: |
Inces |
just use global_position
instead of position
. position counts in local space, which usually is 0,0. When set as top level it no longer referes to another nodes local position, but is set to global 0,0 - which is top left of the screen
Also, usually better practice is to child projectiles to higher scope node like game menager or something, not to the projectile user
Thank you for the suggestion but that didnt work. The fireballs now end up generating at a random distance to the side of the enemy.
YuleTide | 2022-05-09 23:00
Hello with some experimentation I was able to do it, I set a var in the fireball to the global position of the enemies wand, then I created the fireball, then set the fireball as toplevel in its own scripts ready function and then move it to the position held in the var with the enemies wand.
This works, its a bit messy but did the job. Thanks for your suggestion it set me on the path to the solution.
YuleTide | 2022-05-10 11:36
I can’t see the reason it wouldn’t work in easy way 
first set as top level, next :
fireball.global_position = $Position2D.global_position
Did You do exactly that ? 
Remeber, using toplevel your fireball is still childed to the enemy. That means if enemy dies, fireball will disappear too. As I mentioned, it is always better to child projectiles to something neutral 
Hello
Thanks, yes that is exactly what I did but it didnt work for me. I originally thought it was generating the fireballs at random points when I used the code
f.global_position = $Position2D.global_position
but when I zoomed the camera out and experimented a bit I realized that actually what was happening was it was dependant on where the enemy spawned. So for example if the enemy spawned 100 pixels above the zero line on the y axis and 400 pixels from the zero line on the x axis the fireball was appearing 100 pixels above and 400 to the side of the enemy. It was as if it was zeroing the fireball at the enemies wand and then offsetting by how far the enemy spawned from 0,0.
I dont know why but my code seemed to fix it so I am happy with it for now. In future projects I will try doing it your way with the higher scope node to see if that is easier.
YuleTide | 2022-05-10 14:49
I think I know what happened. You instance fireball on enemy ready()
, but shoot them much later. You should create and shoot fireball in the same moment for this to work 
No sorry, the code was in the
func _process(delta)
and creates a fireball each time a variable has been set to true (based on a signal from other nodes).
YuleTide | 2022-05-10 18:53
I bet there is something wrong there 
Your problem i solved, but if You show the whole code of fireball creation and shooting along with signal emission, I can prove there is something wrong with it, if You want 