How to make a stationary "turret" shoot

Godot Version

4.1.2

Question

So i’m looking to make 2 types of “turrets” 1 being something to the effect of the bullet bill cannon from Mario that just fires a bullet a set amount of time, and one that may track the player before firing. But having a bit of a tricky time getting to that point, for the first one would I just set a bullet to be spawned and then go along a set path every few seconds from a Timer? Also how would I make the bullet despawn if it misses the player, would I just time it out after a few seconds? Sorry for a rather stupid question, trying to learn godot 1 step at a time and appreciate any input.

1 Like

If said bullet works the same way it did in super Mario, then you don’t need to worry about it colliding with anything but the player. There’s a node called “VisibleOnScreenNotifier2D” which can be used to check if the bullet is visible on the screen or not, and as soon as it’s not, you can simply call QueueFree on it! As for the path, I’d likely just make it so the bullet has a speed and direction set as soon as it spawns, and just leave it as is. Once it’s outside the screen it will despawn as described above, and if it collides with the player, you can handle that! Here is the relevant documentation page:

1 Like

Oh thank you and very interesting about the visibleOnScreenNotifier, now if there is say a piece of terrain a few “blocks” in front of it that is in the player’s view range, would I just do a similar QueueFree but if it hits a certain object/tile?

If you want a certain wall to block the bullet, you can indeed do the same, and just call queue free on it to remove it, and if you want, just before you do that, you can spawn a fancy effect or explosion as well!

1 Like