0 votes

Here is a code i thinked about:

if (Bullet is spawned/exists for 5 seconds):
Godot version Godot 3.2.3 stable win64
in Engine by (24 points)

3 Answers

0 votes
Best answer

So i found out how to do it, just add timer to object and then this piece of code.

func _ready():
$Timer.connect("timeout", self, "queue_free")

The rest of answers didn't work for idk what reason

by (24 points)
+1 vote

Sure ! You can create a timer for that either by code or by adding Timer node in your Bullet scene. I think you should add a Timer node in your Bullet Scene. How ? Select your Bullet Scene and add a Timer node to it just like you add Sprite, CollisionBody2D etc nodes. After that select that Timer Node and go to Inspector Tab on the rightmost part of engine where you can set the Wait Time to 5 and One Shot to true. After this just go to Node Tab that is on the right side of Inspector tab and under signals connect the timeout to your bullet script. It will create a function in your bullet script where you simply have to add queue_free() statement

You can also make a Timer using code like this :

func _ready():
    bullet_free_timer = Timer.new()
    bullet_free_timer.set_wait_time(5) # 5 seconds wait time
    shoot_timer.connect("timeout", self, "remove_bullet")

func remove_bullet():
by (416 points)
+1 vote

Add a Timer to your bullet

func _ready():
    $Timer.one_shot = true
    $Timer.autostart = true
    $Timer.wait_time = 2.0

func _on_Timer_timeout():
by (638 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.