I believe you put the parent-child relationship for easy access. A parent-child relationship is primarily implemented for the ease of transformation, so if a parent’s transform changes, all children are affected by it.
Solution 1: You need not implement any parent-child relationship if you don’t want the transformation hierarchy.
Solution 2: Godot has additional features like Groups for easier node access. So you can group all the enemies to an “enemy” group and you can call a method on all the enemies at once by
Solution 3: If you want to keep your parent-child relationship for any other matter and also want to move items globally, all you need to put the parent in the world origin i.e., Vector2(0,0) for 2D and Vector3(0,0,0) for 3D, set scale to 1 and set rotation to 0. Then all your child transformations will become the same as global ones.
Solution 4: Then again, if you want the solution 3 and also can’t keep the parent on origin, you can use global transformation functions like
In Godot, hierarchy is far more important than just transforming. It also affects how objects are structured, how they are accessed and inherited. So it makes sense to have a child node drawing things in global space, if that node is part of a scene.
A typical example is particle systems. They explicitely have a
local_space flag just for that.
I’m struggling myself trying to use the
_draw() method to display custom things in global space.
The workaround I use is this:
var inv = get_global_transform().inverse()
draw_set_transform(inv.get_origin(), inv.get_rotation(), inv.get_scale())
And it doesn’t even works if the parent has a negative scale, my drawings get reflected far away beyond the origin of the world…
Note: however, I don’t think bullets should be child of their shooter. 1) because they are instanced, 2) because they interact with the world, not just the shooter.
Zylann | 2016-06-26 14:47
OK. I didn’t think that deep into custom drawing.
So if we build a particle system, with children drawing in global space, how about putting a node at world origin and draw into that.
I usually keep a good structure but will be a little bit flexible. For my projects it does work better.
Thanks for your help , this is an answer that I will bookmark it in my browser …
RezaPouya | 2016-06-26 15:54