0

I'm new to gdscript trying make 2D platformer game in godot3,I'm able to instance a fire scene when the Player node enters the area2D which is im using as field of vision but the scene only instantiate once.How do we keep instancing the fire scene till the player is within the field of vision (Area2D)?

My GDscript :

#monster.gd
func _on_field_of_detection_body_entered(body):#signal passed from Area2D

    if body.name == "Player": # When field of detection detect the player it load the fire.tscn scene.
        var fir = fire.instance()
        fir.set_global_position($fireposition.get_global_position())
        get_parent().add_child(fir)
  • 1
    I have trouble understanding your goal here. What do you mean by "keep instancing"? And when do you want to do that? Do you want to: 1. Instance fire every frame. 2. Instance fire once and remove it manually when the time is right. 3. Instance fire perpetually on custom time interval. Also, when do you want to do that? 1. While player is INSIDE field of detection? 2. While player is OUTSIDE field of detection? – Kobrar Oct 23 '18 at 15:33
  • yes i want monster to keep shooting fire at player when he is inside the field of vision.right now monster only shoots fire once when the player enter the field of vision area and it stops even when the player is still inside. I don't know how to make monster keep shooting fire at player when he enters the area and stop when he exit . – ratan kamath Oct 23 '18 at 18:41
  • Area2D has a method `bool overlaps_body ( Node body ) const`. You can use it in _physics_process to check if player body is within field of detection and do whatever you want with that information. – Kobrar Oct 24 '18 at 02:20
  • @kobrar Thank you it solved my problem it is working now as i wanted. – ratan kamath Oct 24 '18 at 06:38

0 Answers0