Your code isn't formatted correctly :(
Jatz

- May 9, 2021
- Joined Nov 4, 2016
- 0 best answers
use global_position?
From the docs:
the _ready callback is called in reverse order, starting with the children and moving up to the parent nodes
This means that when adding a node to the scene tree, the following order will be used for the callbacks: _enter_tree of the parent, _enter_tree of the children, _ready of the children and finally _ready of the parent (recursively for the entire scene tree).
So you need to listen for
tree_entered
instead. Or you should use call_deferred to add the child.Not enough information
- Edited
Use ViewportTexture https://github.com/CodeDoes/ViewportTextureExample
- Edited
Usually you want the projectile to react to colliding with something.
First it should check wether it is still inside the tree with is_inside_tree, then it should check whether the other object has health or is destructible then decreases health or destroys the other object as applicable. Finally it calls destroys itself with queue_free or something else.
get_parent().remove_child(self) ?
If there's only going to be 1000 bullets then area2d and should be enough
cant really give good advice without a sample project, but i'll give some surface level advice. don't instantiate 50 bullets at once, instantiate them beforehand but keep them deactivated. activate them when you need them. in other words make a pool/cache of bullets. use distance_to_squared then distance_to squared is less accurate but uses less cpu. * regarding gc, i cant really give advice since i don't think i've ever run into the same problem. are you sure its a gc issue?
maybe try writing a godot module in c++ if you are really sure about the lag being caused by the gc. not that hard, even my noob c++ skills can do it when i follow the docs.