This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

How can i interupt a Path2D, for example to talk with a patroling NPC ?

TcheyTchey Posts: 52Member


I have more questions for my "game" (topdown view, adventure game)

---- Path2DFollow
------ NPC (as a KinematicBody2D, instanced) + Script

The NPC also has an Area2D to print text on screen when collision with player.

The script for NPC :

extends KinematicBody2D

func _ready():

func _fixed_process(delta):
   get_parent().set_offset(get_parent().get_offset() + (20*delta))

The script for Aera2D :

extends Area2D

func _on_Area2D_body_enter( body ):
    var textEvent = get_node("/root/Univers/GUI/BoxEvent/EventLog")
    textEvent.add_text("Hello ! ")
    print ("Encounter !")

So the NPC simply follow its path, forever, and when te player moves to the NPC, the text says Hello... All is working so far.

I'd like to make the NPC to stop moving when meeting the player, and move again when the player moves away. I managed to destroy the NPC on collision, but that was a mistake, i swear...

Where to start ?

Thanks for reading.


  • indicainkwellindicainkwell Posts: 13Member

    One way you could do this is by having a switch variable called like is_npc_in_encounter that you switch on and off in the area2D's body enter and body exit signals.

    Then in your fixed_process you can check it with:

    if not is_npc_in_encounter:
        get_parent().set_offset(get_parent().get_offset() + (20*delta))

    Tip! You can have your npc look at your player with the Node2D.look_at() method.

    Hope this helps

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.