Child is rotating with parent and not moving forward

Godot Version

3.5.2

Question

I’m trying to make a cannon that fires bullets, but the bullet does not move and rotates with the cannon. I’ve tried using get_parent().add_child(bullet) to prevent this, but now the bullet spawns to the left and resets its rotation…



(I made the bullet much longer so it is visible)


This one is with get_parent().add_child(bullet)


Here is also the code for the bullet

The reason the bullet rotates with the canon is because it’s a child of the canon, children inherit the parent’s transform (position, scale, rotation). You can use add_sibling to add the bullet next to the canon instead.

Your bullet doesn’t move because it’s never programmed to move. You created the velocity variable inside of _process, it does not affect the Area2D in any except how you use it, which at the moment you only change the y value of the velocity. Since it is local to the func _process velocity is thrown away each frame. Instead change the position of the Area2D

func _process(delta: float) -> void:
    position += transform.x * speed * delta

Why did you choose version 3.5.2 for Godot? Seems like an odd choice for someone just getting into the engine, if you needed 3.x you should’ve downloaded the latest version 3.6.1

3 Likes

I think that generally for bullets or such things of which there can be many on each screen, it can be useful to keep a separate container node. Just a node2d or whatever named “Bullets” or “Enemies”. Even “Players” if multiplayer. The bullets or enemies can then be added as container node children and not inherit movements etc from whatever spawned them. Can also be cleared easily. E.g. if some pickup wipes all enemies out its just loop through the node and have each enemy die.

1 Like

add_sibling didn’t work for me, but i fixed it by changing the bullet’s global_position instead.

as for why I am using an old version of Godot, my laptop is quite old and cannot run the newest versions :frowning: