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?


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

1 Answer

0 votes

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 (2,063 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 [email protected] with your username.