Bullet parenting trick
In Godot if you have a bullet parented to your player, obviously the bullets will move when the player moves.
So you need a node outside of your player hierarchy to parent them to, eg. something like:
- World
- Bullets
- Player
- EnemyA
- EnemyB
This works fine, but can make controlling the bullets a chore due to required boiler plate code.
But… what if you don’t need to do that?
If you put a node of type Node
inside your Player scene it will break the inheritance hierarchy because Node is such a simple type.
In that case you can have:
- Player (Node2D)
- Bullets (Node)
- Bullet (Node2D)
- Bullet (Node2D)
- Bullet (Node2D)
- Bullet (Node2D)
And with this the movement of Player
won’t affect position of Bullets
because the inheritance hierarchy doesn’t work between them.