Combining BattleTanks AI with Behaviour Trees and Blackboard

###Basically, has anyone been able to implement blackboard and behaviour trees in battle tanks?

I’m having a hard time visualising how to go about implementing behaviour tree features into battle tanks while at the same time preserving the AI current implemented that controls the aiming and movement.

In particular I’m thinking of how to have tanks run patrol routes and then once they discover the player default to the current movement / aiming that is already implemented. I’m not looking for a detailed guide but if anyone has done this could you describe the high level process to get something like this done?

Update - Tanks now able to run patrol routes and once player enters the radius of perception the tanks give chase and try and shoot the player. PROBLEM/QUESTION?: What function do I run in blueprint to be able to set the state back to patrolling when the Sentry AI looses sight of the player?

Please note this is still buggy, will update as I make progress.

Inside of TankAIController.h I added the following:

// Enum for AI perception state
UENUM()
enum class EPerceptionStatus : uint8
{
Patrolling, Seeking
};



public:
    UFUNCTION(BlueprintCallable, Category = "State")
    EPerceptionStatus GetPerceptionStatus() const;

    UFUNCTION(BlueprintCallable, Category = "State")
    void SetPerceptionStatus(EPerceptionStatus NextPerceptionStatus);


private:
    //set the default value to patrolling
    UPROPERTY(VisibleAnywhere, Category = "State")
    EPerceptionStatus PerceptionStatus = EPerceptionStatus::Patrolling;

Inside of TankTankAIController.cpp I added this:

void ATankAIController::SetPerceptionStatus(EPerceptionStatus NextPerceptionStatus)
{
    PerceptionStatus = NextPerceptionStatus;
}

EPerceptionStatus ATankAIController::GetPerceptionStatus() const
{
    return PerceptionStatus;
}

Then I placed the current AI code to move/aim/fire inside of the Tick function inside of an if statement in order to see if the state that was set in blueprint was changed to Seeking:

if (PerceptionStatus == EPerceptionStatus::Seeking) {
	
	UE_LOG(LogTemp, Warning, TEXT("Found Enemy, SEARCH AND DESTROY!"))

	// Move towards the player
	MoveToActor(PlayerTank, AcceptanceRadius);  // TODO Check radius is in cm

	// Aim towards the player
	auto AimingComponent = ControlledTank->FindComponentByClass<UTankAimingComponent>();
	AimingComponent->AimAt(PlayerTank->GetActorLocation());

	// If aim & locked Fire towrads the player
	if (AimingComponent->GetFiringState() == EFiringStatus::Locked)
	{
		AimingComponent->Fire(); // TODO limit firing rate
	}
}

Then I hooked up the blueprint as follows:
Blueprint imgur link.

I hope this helps someone out looking into something similar. Ideally I would like to do the entire thing in C++ however there is so little documentation available on OnTargetPerceptionUpdated that I felt a bit intimidated to tackle it just using the comments in the base code.

My next step is to get the tanks to stop following the player once the player has exited their perception radius. I’m happy for any suggestions anyone has.

Blueprint added that turns off blackboard behaviour

I added some things to the blueprint because while testing I discovered that the C++ AI implemented previously was fighting the blackboard behavior each tick and needed to be turned off. I noticed this while playtesting the AI and noticing the path the AI was choosing kept fluttering between the waypoint and the player. This is how I fixed that.

Hey everyone. I went in a different direction with the work because it relied so much on blueprint and I didn’t like that. So I went looking for examples of UE4 AI utilizing C++ and found something almost ideal.

This: Survival sample game by Tom Toolman its a sample series from Epic authered/created by a really tallented guy!

In section 3 of the series, Zombie AI - I was able to utilize his code from the github repo and rework the enemy Tank AI in the same way they had implemented for zombies. Obviously stripping it down to it’s basics and refactoring in such a way to make it usable in the current project.

The enemy tank now randomly chooses waypoints, when it senses the player gives chase and fires, when it loses the player tank in the sense based on a sense timer it resumes patrol. After messing with this for FAR too long yesterday I feel it’s in good working shape ready for post factoring.

Demo of random patrol, search and destroy and resume patrol

Privacy & Terms