_process still triggers after set_process(false) [Godot 3.2]

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By starzar

On setting _process to"false" to trigger an explosion(AnimatedSprite) at the position where a bullet(Area2d) enters an enemy(Rigidbody), the explosion animation doesn’t take place at the collision point ,but way beyond. However,the bullet sprite visibility is set to false ,as soon as the collision is detected.

The explosion sprite inherits its position from the bullet.How to stop _process from triggering once collision has taken place?

#weapon.gd

extends Area2D
    func _process(delta):
    #	if is_processing():  # still _process triggers after collision
    #		position += velocity * delta
	    position += velocity * delta

#bullet.gd

extends weapon.gd
func _on_bullet_body_entered(body):
	set_process(false)
	explosion.position = self.position
	set_deferred("monitoring",false)
    explosion.visible = true
    explosion.playing = true
    bulletsprite.visible = false
:bust_in_silhouette: Reply From: deaton64

Hi,
Not sure why the process it still processing, but you could use a bool for a flag to check if the process should run.

Something like:

var bullet_hit = false

func _process(delta):
    if !bullet_hit:
        move the bullet code
 

func _on_bullet_body_entered(body):
    bullet_hit = true
    explosion etc........