-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBTServic_PlayerLocation.cpp
More file actions
26 lines (20 loc) · 1.1 KB
/
Copy pathBTServic_PlayerLocation.cpp
File metadata and controls
26 lines (20 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Fill out your copyright notice in the Description page of Project Settings.
#include "BTServic_PlayerLocation.h"
#include "GameFramework/Pawn.h"
#include "Kismet/GameplayStatics.h"
#include "BehaviorTree/BlackboardComponent.h"
//for setting the player location in the world so that ai can know the location
UBTServic_PlayerLocation::UBTServic_PlayerLocation()
{
NodeName = "Update Player Location";
}
void UBTServic_PlayerLocation::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
Super::TickNode(OwnerComp, NodeMemory, DeltaSeconds);
//we are calling this function at every frame
APawn* PlayerPawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);//to get the actor to which our ai sees
if (PlayerPawn == nullptr) {
return;
}
OwnerComp.GetBlackboardComponent()->SetValueAsVector(GetSelectedBlackboardKey(), PlayerPawn->GetActorLocation());//function to know the ai about he player location it takes a selectedBlackboardKey and the player pawn which ai wants to see and through that we can get its location using getactorLocation()
}