Be the first to post for 'Sub Behaviour Trees'!

If you’re reading this, there probably aren’t very many posts yet. But don’t worry, you can be the first! Either create a new post or just reply to this one to say ‘hi’.


And you said have some fun right @ben ?

4 Likes

Good effort

1 Like

anti-aliased criminal

2 Likes

hi Ben, I think you are missing a choose next waypoint task in the face next BT

because otherwise the rotate to face will be trying to rotate to face the waypoint that it just arrived at. In the video I think the AI was maneuvering around the cube that caused it to face the correct direction of the other waypoint.

2 Likes

Do keep watching as Sam as been doing significant work on this since

I like this challenge. I also like my guards to be completely unpredictable - maybe they shoot you, maybe they throw bags of gold at you, (maybe I give them guns that shoot bags of gold).

I’ve decided to add a bit of randomness to which behavior tree will be executed when an NPC reaches a patrol point:

The ChooseRandom node is, of course, built using a bit of c++. The header is fairly simple:

UCLASS()
class TESTINGGROUNDS_API UBTTask_ChooseRandom : public UBTTaskNode
{
	GENERATED_BODY()

protected:
	UPROPERTY(EditAnywhere, Category = "Odds")
	float SuccessPercent = 0.5f;

private:
	virtual EBTNodeResult::Type ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override;
};

Its corresponding implementation is equally so:

EBTNodeResult::Type UBTTask_ChooseRandom::ExecuteTask(
	UBehaviorTreeComponent& OwnerComp,
	uint8* NodeMemory)
{
	// Fail within tolerance.
	SuccessPercent = FMath::Clamp<float>(SuccessPercent, 0, 1);

	float Roll = FMath::FRand();

	if (Roll <= SuccessPercent) {
		// Continues the current sub-tree.
		return EBTNodeResult::Succeeded;
	}
	else {
		// Fails the current sub-tree. With a Composite Selector Node
		// this will force the Composite Node to try and execute the
		// next subtree.
		return EBTNodeResult::Failed;
	}
}

I don’t think your Behaviour tree would work properly because it would do this:

  1. Choose where to go
  2. go to location
  3. choose new location
  4. look at the new location
  5. wait
    and then when the cycle is finished, choose a new location and go there.

However I’m having trouble with getting the rotation to work in the first place

My first run of the behavior tree. I have 4 ai characters that share several waypoints in different order. They do a nice job patrolling around this small cell block.

http://screencast-o-matic.com/watch/cbeucn6dy6

Who knew that getting a coke looks a lot like reloading a shotgun.

3 Likes

Hahah!

Privacy & Terms