Add AI Service for Variable Speed Changes

This commit is contained in:
Philip W 2023-10-09 01:48:01 +01:00
parent df7ca8b0db
commit b6fd4e0d75
6 changed files with 55 additions and 5 deletions

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,26 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "BTService_ChangeSpeed.h"
#include "EndlessVendetta/AI/AI_EnemyController.h"
#include "EndlessVendetta/AI/EnemyCharacter.h"
#include "GameFramework/CharacterMovementComponent.h"
UBTService_ChangeSpeed::UBTService_ChangeSpeed()
{
bNotifyBecomeRelevant = true;
NodeName = TEXT("Change Speed");
}
void UBTService_ChangeSpeed::OnBecomeRelevant(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
Super::OnBecomeRelevant(OwnerComp, NodeMemory);
if (const AAI_EnemyController* const EnemyController = Cast<AAI_EnemyController>(OwnerComp.GetAIOwner()))
{
if (const AEnemyCharacter* const EnemyCharacter = Cast<AEnemyCharacter>(EnemyController->GetPawn()))
{
EnemyCharacter->GetCharacterMovement()->MaxWalkSpeed = Speed;
}
}
}

View File

@ -0,0 +1,23 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "BehaviorTree/Services/BTService_BlackboardBase.h"
#include "BTService_ChangeSpeed.generated.h"
/**
*
*/
UCLASS()
class ENDLESSVENDETTA_API UBTService_ChangeSpeed : public UBTService_BlackboardBase
{
GENERATED_BODY()
UBTService_ChangeSpeed();
virtual void OnBecomeRelevant(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory) override;
private:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI", meta = (AllowPrivateAccess = "true"))
float Speed = 600.0f;
};

View File

@ -8,6 +8,7 @@
UBTTask_AttackPlayer::UBTTask_AttackPlayer(FObjectInitializer const& ObjectInitializer)
{
NodeName = TEXT("Attack Player");
}
EBTNodeResult::Type UBTTask_AttackPlayer::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)