Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | dm73994 |
hi, well i have a problem deleting a node (animationSprite2D, its a bullet) from the escene when this collide whit anything,
the problem it’s that when the bullet collide i want to change the animation to a “explosion_bullet”, and then delete the node, i’m using, queue_free(); but this delete the node instandly so the animation “explosion_bullet” never it’s showed, this is my code:
extends KinematicBody2D
#timer to delet the bullet after a lite time to see the "explosion_animation"
var check_time = true;
var cooldown = 3
var timer;
func get_input():
timer= Timer.new();
add_child(timer);
timer.set_one_shot(true);
timer.connect("timeout",self,"_set_check_time");
timer.set_wait_time(cooldown);
func _physics_process(delta):
get_input();
#move_and_slide(velocidad,Vector2(0,0));
var collision_info = move_and_collide(velocidad * delta);
if collision_info && check_time:
delete_bala();
print(check_time)
func delete_bala():
$bala_sprite.animation = ("explosion_bullet");
$bala_sprite.play();
timer.start();
check_time = false
queue_free();
func _set_check_time():
check_time = true;
if there’s another option to improve the code, i would be grateful, i’m just starting and i know that my code it’s not so good in a lot of ways, also the code here it’s not complete, i just put the code from the animation when it’s colliding