How to implement wandering behavior concisely?

caleidon

Member
Hey! Purchased the asset and this is my first post here, ever.

I am learning Behavior Designer and I thought the simplest way would be to start simple, so I tried to implement a BT that picks a random location on a grid and walks to it (using A* Pathfinding Project for pathfinding and movement), then repeats. However, doing this I encountered a problem which I'm not sure about how to solve correctly, so it's more of a question about patterns and how things are done in Behavior Designer.

Here's an image of what I want to do:
Screenshot_1.png
What Wander is supposed to do:
- get a random Vector3Int (the location in the grid)
- walk to that location
- wait a random interval
- repeat

Now, this is a really simple example, so I could just place a Wait task in a sequence next to Wander, but if it got a lot more complex I'm wondering if:

1. Should it be a separate behavior tree, or is there a way to group them and sort of minimize them (expand and collapse)?

2. Next, how should I be getting that random location? Is there any type similar to a conditional task or a decorator task (or perhaps I should use one of those?) that would just return that location, or should I do all of this in the Wander task's OnStart() method, because that's what I'm doing now.

3. Finally, because Wander only needs to get a random location, walk there, and wait, how would I re-use the "walk" task without having to put that entire "walk" code in the Wander action all over again? Should Wander be a seperate behavior tree where I would have a sequence with the Wander Task, which gets a random location in OnStart(), then next in the sequence is the MoveTo task which I can reuse elsewhere, and then finally I can add the Wait task. Then in the main BT, I would link this external WanderBT?

Any input or suggestions are appreciated as I am completely new to Behavior Designer. :)
 
Last edited:
If you don't have the Movement Pack I recommend picking that up as it has a wander task built in :)

For Wander I implemented it as a single task that picks a random location on the navmesh and then moves to the location. The agent keeps picking a new location after the agent has arrived so it always returns a status of running, though it would be easy to change so it would return success after it has arrived the first time.

In your example you should have a similar setup where you just have wander as its own task. Since you are just getting started with the behavior tree flow I recommend taking a look at these resources:

 
Hey, thanks for the reply.

Could you please elaborate a bit more? I don't think you answered question 3 fully.

If I made a "MoveTo" task which was very complex and handled all sorts of scenarios, why would I copy that entire code into the "Wander" task, which just adds random position selection and waiting? My question was mostly what's the proper way to re-use tasks (or actions, not sure what the proper terminology is).

Here's what I mean:
Screenshot_1.png

The main BT calls the Wander external BT, which can then re-use the MoveTo task and the Wait task that's already built in, but just additionally adds "Pick next location" task.

Would this be a good way of doing things?
 
Ah, I see. Yes, grouping the tasks into an external behavior tree and then reusing them with the behavior tree reference task is definitely a good strategy.
 
Could you use the Wander and select a specific location to go to using the movement pack alongside the A* Pathfinder?

(It would probably still require a pop up map for the user to click the location).

Is there a description of each of the Movement pack tasks?
 
Last edited:
Wander is completely random so wandering to a point isn't built in. With some coding it definitely would be possible though.

Is there a description of each of the Movement pack tasks?
When you add the task there is a short description of what it does on the bottom of the window.
 
Top