0 votes

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
in Engine by (49 points)

1 Answer

0 votes

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........
by (1,861 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 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.