News Forums Sample Projects, How To’s, and Code Samples BT node Patrol Waypoints repeating

This topic contains 6 replies, has 2 voices, and was last updated by  prime 3 weeks, 4 days ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #34459

    Jaroslav
    Participant

    Hello,

    in my BT, I have 3 states : walk, hit (when hit by a gun), shooting (when last shor was fired before less than 5 seconds). I use one Patrol Route node, as seen below.


    * do not consider yield node, just mistake

    Before that I used this one:

    The problem is (with both), thah when I have let’s say 5 waypoints in my waypoint rig and I use these BTs, everything is OK, until I change state (walk -> hit, hit -> walk, …). In that case, my AI skips one waypoint.
    Ex.:
    OK: 1 -> 2 -> 3 -> 4 -> 5
    Mine: 1 -> 2 (change state to shooting) -> 3 (change state back to walk) -> 5
    It looks like nextStep (next waypoints var) is increased one more time than it should be when changing states.

    In the BT where I had separate waypoint nodes for each state it was even more complicated. It looked like each state had its own nextStep and example run looked like: 1 (change to hit) -> 2 (change to walk) -> 2 -> 3 (change to hit) -> 3 -> ….

    I guees this is complex issue and my explanation is very confusing, so please, if anything is not clear, just ask me and I will explain.

    Thank you!

    #34465

    prime
    Keymaster

    Here’s how the waypoint routes/nodes work:

    1) When the node first runs, it determines which waypoint you are starting from/moving toward and sets that as the waypoint move target.

    2) The waypoint node will then run its child nodes. Those child nodes can be ANYTHING - as shown in @Jaroslav example. The child nodes are run like a Sequencer, one after the other.

    3) If any child node fails, the Waypoint node will fail immediately. (just like a sequencer)

    4) If all the child nodes succeed, the Waypoint node will then select the next waypoint in the sequence, set that as a waypoint move target, and repeat.

    5) This continues either forever (for looping Waypoints nodes) or until the final waypoint is reached.

    Note that the Waypoint node itself never checks to see if the AI physically reaches the waypoint. It is up to the child nodes to make that determination and only return success once the waypoint is reached.

    In your case @Jaroslav, you will want to set up the child BT under your Waypoint route to only return Success from a moving state. If you are changing state from shooting to walking, you may want to set up a repeater or some other guard to make sure the death selector can’t return success there.

    #34482

    Jaroslav
    Participant

    I was trying to wrap my head around what you wrote since you’ve written it, but I’m not getting it.

    Could you please post some example?

    Also, I would like to ask, what does it mean, that Waypoint node fails? And I still don’t understand, why BT I posted in first picture doesn’t work. If you could explain this, maybe it would make more sense to me.

    Thank you!

    • This reply was modified 3 weeks, 4 days ago by  Jaroslav.
    #34488

    prime
    Keymaster

    If I understand your behavior tree correctly, it contains 3 basic states: run when you aren’t shooting, walk when you are shooting, and a hit animation when you are hit.

    With the way your logic is set up, whenever you leave the shooting or hit states, the top level selector under the Waypoint node will stop running. This happens because either (a) you stop shooting or stop being hit, which makes the Constraint node fail and the selector parent fail, or (b) you actually reach your destination while moving, which makes the whole subtree succeed.

    If your selector fails from (a), then the entire Waypoint node will fail and reset. In some cases, that can result in skipping a node.

    What you probably want to do instead is separate your Movement from your Animation entirely. Under your Waypoint node, create a parallel. Let that parallel succeed on Any. Inside the parallel, add a selector which manages two things: (1) the animation you are playing based on running/shooting/being hit, and (2) sets a variable indicating how fast the move node should be moving. Make that selector repeat forever. Add another node to the parallel. This will be your Move node. Make sure the Move node uses the speed variable set in the selector.

    With this setup, the only way your Parallel can finish is if the Move node succeeds or fails (it should always succeed). That will only happen when you have reached your waypoint target.

    Hope that helps

    #34492

    Jaroslav
    Participant

    My current BT. Not working :(. I guess I’m still missing something important.

    Current behavior: when NPC runs, it’s OK, when I shoot, it changes state to shooting and it’s OK, but when it returns back to run state (automatically after 5 secs without shooting) and it’s on its way from let’s say 3rd to 4th waypoint, it returns to 3rd one and just after that continues it’s way to 4th waypoint. If I shoot number of times, when in shooting states the bahavior is even more complicated.

    #34493

    Jaroslav
    Participant

    I cannot edit my post, so I’m posting new post.

    Looks like I finally got it! Here’s my working BT.

    Thanks for the idea about moving and animating/setting speed in different places, I think it was the icebreaker!

    • This reply was modified 3 weeks, 4 days ago by  Jaroslav.
    #34496

    prime
    Keymaster

    Awesome. Nice work.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.