Announcement

Collapse
No announcement yet.

Behavior Tree Problem

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Behavior Tree Problem

    Hi. Im trying to understand the Behavior Tree. I started with the tutorial https://docs.unrealengine.com/latest...art/index.html. Then i noticed that AI behaves oddly, and i checked everything pretty closely.

    Then i stripped BT down little bit to understand it better.

    Click image for larger version

Name:	BT.png
Views:	1
Size:	50.3 KB
ID:	1205051

    Click image for larger version

Name:	AIMoveTo.png
Views:	1
Size:	79.8 KB
ID:	1205052

    But AI still keeps chasing player while he is away from the sphere trace.

    Click image for larger version

Name:	Service.png
Views:	1
Size:	103.1 KB
ID:	1205053

    Then i dumped the AIMoveTo and changed it to VInterp, but it doesnt even work a bit.

    Click image for larger version

Name:	VInterp.png
Views:	1
Size:	100.2 KB
ID:	1205054

    So what is going wrong with this? Im trying to stop the AI from following when it is out from the reach.
    http://www.kakepla.net

    #2
    Could you explain in plain text the behavior that you want your NPC to perform?

    WIP Thread

    Comment


      #3
      It cannot work. Receive execute is called every frame, your new tasks will end immediately, with success. AIMoveTo has a little watch icon on it, meaning that OnSuccess is only called when the actual move is completely finished. Until then finish execute is not called, so the BT stays in the same node, so the pawn continues to move frame after frame. Your task will call SetLocation once then call finish execute, so the BT will end too (or loop, whatever). You have to put some condition in your code, like distance to target, then call FinishExecute only when it's met.
      Snap Plugin for EditorSnap Plugin for Games
      Modular Japanese HouseScaffold System
      TwitterBlogYoutubeitch.io

      Comment


        #4
        "It cannot work. Receive execute is called every frame, your new tasks will end immediately, with success. AIMoveTo has a little watch icon on it, meaning that OnSuccess is only called when the actual move is completely finished. Until then finish execute is not called, so the BT stays in the same node, so the pawn continues to move frame after frame. Your task will call SetLocation once then call finish execute, so the BT will end too (or loop, whatever). You have to put some condition in your code, like distance to target, then call FinishExecute only when it's met."

        Oh, now i understand that.

        "Could you explain in plain text the behavior that you want your NPC to perform?"

        Initially i followed BT tutorial, which is Epics standard tutorial. Whit that tutorial AI never stopped chasing the player, which led to this problem. I want AI to stop the chase when player is out of reach of sphere trace. Somehow blackboard entry (TargetToHunt) never changes back to empty, or if it does, it doesnt matter.
        http://www.kakepla.net

        Comment


          #5
          No progress so far. I think BT is working correctly.

          Click image for larger version

Name:	BT.png
Views:	1
Size:	73.4 KB
ID:	1121085

          When stepping out from the reach.

          Click image for larger version

Name:	BT2.png
Views:	1
Size:	69.6 KB
ID:	1121086

          But AI Move To never stops walking.

          Click image for larger version

Name:	AIMoveTo.png
Views:	1
Size:	106.4 KB
ID:	1121087
          http://www.kakepla.net

          Comment


            #6
            You have condition "TargetToHunt is not set". Do you clear TargetToHunt somewhere? Also when your BT node is aborted AIMoveTo will continue. You need to abort it in the ReceiveAbort event (I don't remember what to call to abort it) or you can use MoveTo predefined BT task, it manages all that.

            BTW, i was wrong yesterday, "Receive execute" is called just once, tick event is called every frame. But that don't change anything in this case.
            Snap Plugin for EditorSnap Plugin for Games
            Modular Japanese HouseScaffold System
            TwitterBlogYoutubeitch.io

            Comment


              #7
              Yes, Target To Hunt is cleared and BB shows there is None when player moves out of the range. MoveTo worked, but i might need to use own movement task to get more customization. That AIMoveTo is pretty scary thing, which leads to write own movement routine (if i sometime get even a little bit skills). And i dont know anything about Event Receive Abort, how and where to use it. If there will be own movement routine, does it mean the AI cant navigate NavMesh same style as AIMoveTo? I post results when i got something.
              http://www.kakepla.net

              Comment


                #8
                Ok, now i got it. I dug some Google and found a sample how to use the abort.

                Click image for larger version

Name:	Abort.png
Views:	1
Size:	131.2 KB
ID:	1121089

                I think now it works. Thx for the help!
                http://www.kakepla.net

                Comment


                  #9
                  ReceiveAbort is just another event of BT task, but it's not shown by default like Event Receive Execute. Left click and search for it. MoveTo is just a wrapper around AIMoveTo, but it handles abort too. AIMoveTo is the function that navigates the navmesh. I don't know if you can navigate it other way. I believe you can use something like "FindPath" (don't remember the exact name) then use it to navigate, but it seems to be even more complicated.

                  AIMoveTo will start the movement then notify you how it goes. OnSuccess/OnFail will be called once the movement is completed. MovementResult struct gives you more info about how it goes.
                  Last edited by scha; 01-08-2017, 08:10 AM. Reason: was wrong about first pin
                  Snap Plugin for EditorSnap Plugin for Games
                  Modular Japanese HouseScaffold System
                  TwitterBlogYoutubeitch.io

                  Comment

                  Working...
                  X