_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?


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


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

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........