本文整理汇总了C++中APawn::GetActorLocation方法的典型用法代码示例。如果您正苦于以下问题:C++ APawn::GetActorLocation方法的具体用法?C++ APawn::GetActorLocation怎么用?C++ APawn::GetActorLocation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类APawn
的用法示例。
在下文中一共展示了APawn::GetActorLocation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Tick
void ADuckTower::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
/*
AActor *actor = GetAttachParentActor();
FVector actor2 = UGameplayStatics::GetPlayerController(GetWorld(), 0)->GetControlledPawn()->GetActorLocation();
FRotator newRotation = FRotationMatrix::MakeFromX(actor2 - actor->GetActorLocation()).Rotator();
GetAttachParentActor()->SetActorRotation(newRotation);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, actor->GetName());
*//*
FVector actor2 = UGameplayStatics::GetPlayerController(GetWorld(), 0)->GetControlledPawn()->GetActorLocation();
FVector actor = GetAttachParentActor()->GetActorLocation();
FVector Direction = actor - actor2;
FRotator test = FRotationMatrix::MakeFromX(Direction).Rotator();
GetAttachParentActor()->SetActorRotation(test);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, actor2.ToString());
*/
//GetAttachParentActor()->SetActorLocation(FVector(0.0f, 0.0f, (float)testNumber));
//testNumber += 1.f;
APawn *player = UGameplayStatics::GetPlayerController(GetWorld(), 0)->GetControlledPawn();
FVector actor2 = player->GetActorLocation(); //+ player->GetRootPrimitiveComponent()->GetPhysicsLinearVelocity() *DeltaSeconds * 10;
FVector actor = GetActorLocation();
FVector Direction = actor - actor2;
FRotator test = FRotationMatrix::MakeFromX(Direction).Rotator();
FRotator test2 = FRotator(1.0f, 0.0f, 0.0f);
FRotator finalrot = FRotator(test.Quaternion() * test2.Quaternion());
FVector vec2 = UGameplayStatics::GetPlayerController(GetWorld(), 0)->GetControlledPawn()->GetActorLocation();
FVector vec = GetActorLocation();
float distance = FVector::Dist(actor, actor2);
//finalrot.Pitch -= 10 - distance / 10000 * 10;
//SetActorRotation(finalrot);
TArray<UStaticMeshComponent*> comps;
GetComponents(comps);
/*
for (auto StaticMeshComponent : comps)
{
StaticMeshComponent->SetVisibility(true);
StaticMeshComponent->SetWorldRotation(finalrot);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, StaticMeshComponent->GetComponentRotation().ToString());
}*/
if (UGameplayStatics::GetPlayerController(GetWorld(), 0)->WasInputKeyJustPressed(EKeys::I))
{
}
if (shootTimer <= 0.f)
{
Shoot(distance);
shootTimer = 2.f;
}
else
shootTimer -= DeltaSeconds;
//GetAttachParentActor()->GetRootPrimitiveComponent()->AddImpulse(UGameplayStatics::GetPlayerController(GetWorld(), 0)->GetControlledPawn()->GetActorForwardVector());
//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::FromInt(testNumber));
//GetAttachParentActor()->SetActorRotation()
}
示例2: SearchForEnemy
/**
Function called to search for an enemy
- parameter void:
- returns: void
*/
void AEnemyController::SearchForEnemy()
{
APawn* MyEnemy = GetPawn();
if (MyEnemy == NULL)
return;
const FVector MyLoc = MyEnemy->GetActorLocation();
float BestDistSq = MAX_FLT;
ATankCharacter* BestPawn = NULL;
for (FConstPawnIterator It = GetWorld()->GetPawnIterator(); It; It++)
{
ATankCharacter* TestPawn = Cast<ATankCharacter>(*It);
if (TestPawn)
{
const float DistSq = FVector::Dist(TestPawn->GetActorLocation(), MyLoc);
bool canSee = LineOfSightTo(TestPawn);
//choose the closest option to the AI that can be seen
if (DistSq < BestDistSq && canSee)
{
BestDistSq = DistSq;
BestPawn = TestPawn;
}
}
}
if (BestPawn)
{
GEngine->AddOnScreenDebugMessage(0, 1.0f, FColor::Green, BestPawn->GetName());
SetEnemy(BestPawn);
}
}
示例3: GetActorLocation
FExecStatus FCameraCommandHandler::GetActorLocation(const TArray<FString>& Args)
{
APawn* Pawn = FUE4CVServer::Get().GetPawn();
FVector CameraLocation = Pawn->GetActorLocation();
FString Message = FString::Printf(TEXT("%.3f %.3f %.3f"), CameraLocation.X, CameraLocation.Y, CameraLocation.Z);
return FExecStatus::OK(Message);
}
示例4: FindClosestEnemy
void AFournoidAIController::FindClosestEnemy(){
APawn* MyBot = GetPawn();
if (MyBot == NULL)
{
return;
}
const FVector MyLoc = MyBot->GetActorLocation();
float BestDistSq = MAX_FLT;
AFournoidCharacter* BestPawn = NULL;
for (FConstPawnIterator It = GetWorld()->GetPawnIterator(); It; ++It)
{
AFournoidCharacter* TestPawn = Cast<AFournoidCharacter>(*It);
if (TestPawn && TestPawn->IsAlive() && TestPawn->GetController()->IsA(APlayerController::StaticClass()))
{
const float DistSq = (TestPawn->GetActorLocation() - MyLoc).SizeSquared();
if (DistSq < BestDistSq && sqrt(DistSq) < 2500.f )
{
BestDistSq = DistSq;
BestPawn = TestPawn;
}
}
}
if (BestPawn)
{
SetEnemy(BestPawn);
}else {
SetEnemy(NULL);
}
}
示例5: SpawnVehicleAttempt
void AVehicleSpawnerBase::SpawnVehicleAttempt()
{
if(Vehicles.Num()>=NumberOfVehicles)
{
UE_LOG(LogCarla, Log, TEXT("All vehicles spawned correctly"));
return;
}
APlayerStart* spawnpoint = GetRandomSpawnPoint();
APawn* playerpawn = UGameplayStatics::GetPlayerPawn(GetWorld(),0);
const float DistanceToPlayer = playerpawn&&spawnpoint? FVector::Distance(playerpawn->GetActorLocation(),spawnpoint->GetActorLocation()):0.0f;
float NextTime = TimeBetweenSpawnAttemptsAfterBegin;
if(DistanceToPlayer>DistanceToPlayerBetweenSpawnAttemptsAfterBegin)
{
if(SpawnVehicleAtSpawnPoint(*spawnpoint)!=nullptr)
{
UE_LOG(LogCarla, Log, TEXT("Vehicle %d/%d late spawned"), Vehicles.Num(), NumberOfVehicles);
}
} else
{
NextTime /= 2.0f;
}
if(Vehicles.Num()<NumberOfVehicles)
{
auto &timemanager = GetWorld()->GetTimerManager();
if(AttemptTimerHandle.IsValid()) timemanager.ClearTimer(AttemptTimerHandle);
timemanager.SetTimer(AttemptTimerHandle,this, &AVehicleSpawnerBase::SpawnVehicleAttempt,NextTime,false,-1);
} else
{
UE_LOG(LogCarla, Log, TEXT("All vehicles spawned correctly"));
}
}
示例6: Shoot
void ADuckTower::Shoot(float distance)
{
/*
const FName filename = FName(TEXT("Blueprint'/Game/Blueprints/PickUp.PickUp'"));
FVector loc = GetAttachParentActor()->GetActorLocation();
FRotator rot = GetAttachParentActor()->GetActorRotation();
SpawnBP(GetWorld(), (UClass*)LoadObjFromPath<UBlueprint>(&filename), loc, rot);
*/
APawn *player = UGameplayStatics::GetPlayerController(GetWorld(), 1)->GetControlledPawn();
int randomValue = distance / 10000;
FVector vec = player->GetActorLocation() + FVector(FMath::RandRange(-randomValue, randomValue), FMath::RandRange(-randomValue, randomValue), 0.0f); //+ player->GetRootPrimitiveComponent()->GetPhysicsLinearVelocity() *DeltaSeconds * 10;
FVector vec2 = GetActorLocation();
FVector Direction = vec - vec2;
FRotator test = FRotationMatrix::MakeFromX(Direction).Rotator();
FRotator test2 = FRotator(1.0f, 0.0f, 0.0f);
FRotator finalrot = FRotator(test.Quaternion() * test2.Quaternion());
FVector forward = GetActorForwardVector();
finalrot.Roll = -finalrot.Roll;
finalrot.Yaw = -finalrot.Yaw;
finalrot.Pitch = -finalrot.Pitch;
FVector loc = GetActorLocation() + forward * 500.0f;
FRotator rot = GetActorRotation();
AActor* actor = GetWorld()->SpawnActor<AActor>(BulletBlueprint, loc, GetActorRotation());
actor->SetActorScale3D(FVector(3.0f, 3.0f, 3.0f));
//actor->GetRootPrimitiveComponent()->AddImpulse(actor->GetActorForwardVector()* 5000.0f);
//actor->GetRootPrimitiveComponent()->SetPhysicsLinearVelocity(actor->GetActorForwardVector()*10000.0f); //* (distance/10000 * 1.0f));
}
示例7: DrawOverHeadInformation
void AGameplayDebuggingHUDComponent::DrawOverHeadInformation(APlayerController* PC, class UGameplayDebuggingComponent *DebugComponent)
{
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
APawn* MyPawn = Cast<APawn>(DebugComponent->GetSelectedActor());
const FVector Loc3d = MyPawn ? MyPawn->GetActorLocation() + FVector(0.f, 0.f, MyPawn->GetSimpleCollisionHalfHeight()) : FVector::ZeroVector;
if (OverHeadContext.Canvas->SceneView == NULL || OverHeadContext.Canvas->SceneView->ViewFrustum.IntersectBox(Loc3d, FVector::ZeroVector) == false)
{
return;
}
const FVector ScreenLoc = OverHeadContext.Canvas->Project(Loc3d);
static const FVector2D FontScale(1.f, 1.f);
UFont* Font = GEngine->GetSmallFont();
float TextXL = 0.f;
float YL = 0.f;
FString ObjectName = FString::Printf( TEXT("{yellow}%s {white}(%s)"), *DebugComponent->ControllerName, *DebugComponent->PawnName);
CalulateStringSize(OverHeadContext, OverHeadContext.Font, ObjectName, TextXL, YL);
bool bDrawFullOverHead = MyPawn != nullptr && GetDebuggingReplicator()->GetSelectedActorToDebug() == MyPawn;
float IconXLocation = OverHeadContext.DefaultX;
float IconYLocation = OverHeadContext.DefaultY;
if (bDrawFullOverHead)
{
OverHeadContext.DefaultX -= (0.5f*TextXL*FontScale.X);
OverHeadContext.DefaultY -= (1.2f*YL*FontScale.Y);
IconYLocation = OverHeadContext.DefaultY;
OverHeadContext.CursorX = OverHeadContext.DefaultX;
OverHeadContext.CursorY = OverHeadContext.DefaultY;
}
if (DebugComponent->DebugIcon.Len() > 0)
{
UTexture2D* RegularIcon = (UTexture2D*)StaticLoadObject(UTexture2D::StaticClass(), NULL, *DebugComponent->DebugIcon, NULL, LOAD_NoWarn | LOAD_Quiet, NULL);
if (RegularIcon)
{
FCanvasIcon Icon = UCanvas::MakeIcon(RegularIcon);
if (Icon.Texture)
{
const float DesiredIconSize = bDrawFullOverHead ? 32.f : 16.f;
DrawIcon(OverHeadContext, FColor::White, Icon, IconXLocation, IconYLocation - DesiredIconSize, DesiredIconSize / Icon.Texture->GetSurfaceWidth());
}
}
}
if (bDrawFullOverHead)
{
OverHeadContext.FontRenderInfo.bEnableShadow = bDrawFullOverHead;
PrintString(OverHeadContext, bDrawFullOverHead ? FColor::White : FColor(255, 255, 255, 128), FString::Printf(TEXT("%s\n"), *ObjectName));
OverHeadContext.FontRenderInfo.bEnableShadow = false;
}
if (EngineShowFlags.DebugAI)
{
DrawPath(PC, DebugComponent);
}
#endif //!(UE_BUILD_SHIPPING || UE_BUILD_TEST)
}
示例8: SelectTargetToDebug
void AGameplayDebuggerReplicator::SelectTargetToDebug()
{
#if ENABLED_GAMEPLAY_DEBUGGER
APlayerController* MyPC = DebugCameraController.IsValid() ? DebugCameraController.Get() : GetLocalPlayerOwner();
if (MyPC)
{
float bestAim = 0;
FVector CamLocation;
FRotator CamRotation;
check(MyPC->PlayerCameraManager != nullptr);
MyPC->PlayerCameraManager->GetCameraViewPoint(CamLocation, CamRotation);
FVector FireDir = CamRotation.Vector();
UWorld* World = MyPC->GetWorld();
check(World);
APawn* PossibleTarget = nullptr;
for (FConstPawnIterator Iterator = World->GetPawnIterator(); Iterator; ++Iterator)
{
APawn* NewTarget = *Iterator;
if (NewTarget == nullptr || NewTarget == MyPC->GetPawn()
|| (NewTarget->PlayerState != nullptr && NewTarget->PlayerState->bIsABot == false)
|| NewTarget->GetActorEnableCollision() == false)
{
continue;
}
if (NewTarget != MyPC->GetPawn())
{
// look for best controlled pawn target
const FVector AimDir = NewTarget->GetActorLocation() - CamLocation;
float FireDist = AimDir.SizeSquared();
// only find targets which are < 25000 units away
if (FireDist < 625000000.f)
{
FireDist = FMath::Sqrt(FireDist);
float newAim = FVector::DotProduct(FireDir, AimDir);
newAim = newAim / FireDist;
if (newAim > bestAim)
{
PossibleTarget = NewTarget;
bestAim = newAim;
}
}
}
}
if (PossibleTarget != nullptr && PossibleTarget != LastSelectedActorToDebug)
{
ServerSetActorToDebug(Cast<AActor>(PossibleTarget));
}
}
#endif //ENABLED_GAMEPLAY_DEBUGGER
}
示例9: AddCinePawn
void ACinemotusPlayerController::AddCinePawn()
{
// pawnToAdd->
APawn* pawnToAdd = NULL;
int newIndex = 0;
while (newIndex < PawnsInScene.Num() &&!PawnsInScene[newIndex]->bHidden)
{
newIndex++;
}//keep going till we find a hidden one
if (newIndex >= PawnsInScene.Num())
{
//add a dude
UWorld* const World = GetWorld();
if (World)
{
// Set the spawn parameters
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.Instigator = Instigator;
// Get a random location to spawn at
FVector SpawnLocation = GetPawn()->GetActorLocation();
// Get a random rotation for the spawned item
FRotator SpawnRotation = GetPawn()->GetActorRotation();
// spawn the pickup
pawnToAdd = GetWorld()->SpawnActor<ACinemotusDefaultPawn>(ACinemotusDefaultPawn::StaticClass(), SpawnLocation, SpawnRotation, SpawnParams);
}
}
else
{
pawnToAdd = PawnsInScene[newIndex];
APawn* pwn = GetPawn();
pawnToAdd->SetActorLocationAndRotation(pwn->GetActorLocation(), pwn->GetActorRotation()); //make this one added to where we are right now
}
pawnToAdd->SetActorTickEnabled(true);
pawnToAdd->SetActorEnableCollision(true);
pawnToAdd->SetActorHiddenInGame(false);
SwitchToPawn(pawnToAdd);
}
示例10: MakeNoise
void UPawnNoiseEmitterComponent::MakeNoise(AActor* NoiseMaker, float Loudness, const FVector& NoiseLocation)
{
if (!NoiseMaker || Loudness <= 0.f)
{
return;
}
// Get the Pawn that owns us, either directly or through a possible Controller owner.
AActor* Owner = GetOwner();
APawn* PawnOwner = Cast<APawn>(Owner);
if (PawnOwner == NULL)
{
AController* OwnerController = Cast<AController>(Owner);
if (IsValid(OwnerController))
{
PawnOwner = OwnerController->GetPawn();
}
}
// only emit sounds from pawns with controllers
if (!IsValid(PawnOwner) || !PawnOwner->Controller)
{
return;
}
// Was this noise made locally by this pawn?
if ( NoiseMaker == PawnOwner || ((PawnOwner->GetActorLocation() - NoiseLocation).SizeSquared() <= FMath::Square(PawnOwner->GetSimpleCollisionRadius())) )
{
// use loudest noise within NoiseLifetime
// Do not reset volume to zero after time has elapsed; sensors detecting the sound can choose for themselves how long to care about sounds.
const bool bNoiseExpired = (GetWorld()->GetTimeSeconds() - LastLocalNoiseTime) > NoiseLifetime;
if (bNoiseExpired || Loudness >= LastLocalNoiseVolume)
{
LastLocalNoiseVolume = Loudness;
LastLocalNoiseTime = GetWorld()->GetTimeSeconds();
}
}
// noise is not local - use loudest in this period
else
{
const bool bNoiseExpired = (GetWorld()->GetTimeSeconds() - LastRemoteNoiseTime) > NoiseLifetime;
if (bNoiseExpired || Loudness >= LastRemoteNoiseVolume)
{
LastRemoteNoiseVolume = Loudness;
LastRemoteNoisePosition = NoiseLocation;
LastRemoteNoiseTime = GetWorld()->GetTimeSeconds();
}
}
}
示例11: GetCameraPose
FExecStatus FCameraCommandHandler::GetCameraPose(const TArray<FString>& Args)
{
if (Args.Num() == 1)
{
bool bIsMatinee = false;
FVector CameraLocation;
FRotator CameraRotation;
ACineCameraActor* CineCameraActor = nullptr;
for (AActor* Actor : this->GetWorld()->GetCurrentLevel()->Actors)
{
// if (Actor && Actor->IsA(AMatineeActor::StaticClass())) // AMatineeActor is deprecated
if (Actor && Actor->IsA(ACineCameraActor::StaticClass()))
{
bIsMatinee = true;
CameraLocation = Actor->GetActorLocation();
CameraRotation = Actor->GetActorRotation();
break;
}
}
if (!bIsMatinee)
{
// int32 CameraId = FCString::Atoi(*Args[0]); // TODO: Add support for multiple cameras
// This should support multiple cameras
// UGTCaptureComponent* CaptureComponent = FCaptureManager::Get().GetCamera(CameraId);
// if (CaptureComponent == nullptr)
// {
// return FExecStatus::Error(FString::Printf(TEXT("Camera %d can not be found."), CameraId));
// }
// CameraLocation = CaptureComponent->GetComponentLocation();
// CameraRotation = CaptureComponent->GetComponentRotation();
APawn* Pawn = FUE4CVServer::Get().GetPawn();
CameraLocation = Pawn->GetActorLocation();
CameraRotation = Pawn->GetControlRotation();
}
FString Message = FString::Printf(TEXT("%.3f %.3f %.3f %.3f %.3f %.3f"),
CameraLocation.X, CameraLocation.Y, CameraLocation.Z,
CameraRotation.Pitch, CameraRotation.Yaw, CameraRotation.Roll);
return FExecStatus::OK(Message);
}
return FExecStatus::Error("Number of arguments incorrect");
}
示例12: CollectDataToReplicate
void UPerceptionGameplayDebuggerObject::CollectDataToReplicate(APlayerController* MyPC, AActor *SelectedActor)
{
Super::CollectDataToReplicate(MyPC, SelectedActor);
#if ENABLED_GAMEPLAY_DEBUGGER
if (GetWorld()->TimeSeconds - LastDataCaptureTime < 2)
{
return;
}
APawn* MyPawn = Cast<APawn>(SelectedActor);
if (MyPawn)
{
AAIController* BTAI = Cast<AAIController>(MyPawn->GetController());
if (BTAI)
{
UAIPerceptionComponent* PerceptionComponent = BTAI->GetAIPerceptionComponent();
if (PerceptionComponent == nullptr)
{
PerceptionComponent = MyPawn->FindComponentByClass<UAIPerceptionComponent>();
}
if (PerceptionComponent)
{
TArray<FString> PerceptionTexts;
GenericShapeElements.Reset();
PerceptionComponent->GrabGameplayDebuggerData(PerceptionTexts, GenericShapeElements);
DistanceFromPlayer = DistanceFromSensor = -1;
if (MyPC && MyPC->GetPawn())
{
DistanceFromPlayer = (MyPawn->GetActorLocation() - MyPC->GetPawn()->GetActorLocation()).Size();
DistanceFromSensor = SensingComponentLocation != FVector::ZeroVector ? (SensingComponentLocation - MyPC->GetPawn()->GetActorLocation()).Size() : -1;
}
}
UAIPerceptionSystem* PerceptionSys = UAIPerceptionSystem::GetCurrent(MyPawn->GetWorld());
if (PerceptionSys)
{
PerceptionLegend = PerceptionSys->GetPerceptionDebugLegend();
}
}
}
#endif
}
示例13: CollectData
void FGameplayDebuggerCategory_Navmesh::CollectData(APlayerController* OwnerPC, AActor* DebugActor)
{
#if WITH_RECAST
ARecastNavMesh* NavData = nullptr;
APawn* PlayerPawn = OwnerPC ? OwnerPC->GetPawnOrSpectator() : nullptr;
APawn* DebugActorAsPawn = Cast<APawn>(DebugActor);
APawn* DestPawn = DebugActorAsPawn ? DebugActorAsPawn : PlayerPawn;
if (DestPawn)
{
UNavigationSystem* NavSys = UNavigationSystem::GetCurrent(OwnerPC->GetWorld());
const FNavAgentProperties& NavAgentProperties = DestPawn->GetNavAgentPropertiesRef();
NavData = Cast<ARecastNavMesh>(NavSys->GetNavDataForProps(NavAgentProperties));
}
if (NavData)
{
// add 3x3 neighborhood of target
const FVector TargetLocation = DestPawn->GetActorLocation();
TArray<int32> TileSet;
int32 TileX = 0;
int32 TileY = 0;
const int32 DeltaX[] = { 0, 1, 1, 0, -1, -1, -1, 0, 1 };
const int32 DeltaY[] = { 0, 0, 1, 1, 1, 0, -1, -1, -1 };
int32 TargetTileX = 0;
int32 TargetTileY = 0;
NavData->GetNavMeshTileXY(TargetLocation, TargetTileX, TargetTileY);
for (int32 Idx = 0; Idx < ARRAY_COUNT(DeltaX); Idx++)
{
const int32 NeiX = TargetTileX + DeltaX[Idx];
const int32 NeiY = TargetTileY + DeltaY[Idx];
NavData->GetNavMeshTilesAt(NeiX, NeiY, TileSet);
}
const int32 DetailFlags =
(1 << static_cast<int32>(ENavMeshDetailFlags::PolyEdges)) |
(1 << static_cast<int32>(ENavMeshDetailFlags::FilledPolys)) |
(1 << static_cast<int32>(ENavMeshDetailFlags::NavLinks));
NavmeshRenderData.GatherData(NavData, DetailFlags, TileSet);
}
#endif // WITH_RECAST
}
示例14: SearchForEnemy
// Function to set the bot's target to the closest player-controlled tank
void ABotController::SearchForEnemy()
{
APawn* MyBot = GetPawn();
ABot* Tank = Cast<ABot>(GetPawn());
if (MyBot == NULL)
return;
//indicate the that the game has now started
BlackboardComp->SetValue<UBlackboardKeyType_Bool>(HasStartedID, true);
const FVector MyLoc = MyBot->GetActorLocation();
float BestDistSq = MAX_FLT;
//Iterate through the world objects, and set the closest found player to BestPawn
for (FConstPawnIterator It = GetWorld()->GetPawnIterator(); It; It++)
{
ATank* TestPawn = Cast<ATank>(*It);
if (TestPawn)
{
const float DistSq = FVector::Dist(TestPawn->GetActorLocation(), MyLoc);
if (DistSq < BestDistSq)
{
BestDistSq = DistSq;
BestPawn = TestPawn;
if (PawnCanBeSeen(*It)){
FRotator Rot = FRotationMatrix::MakeFromX(BestPawn->GetActorLocation() - Tank->GetActorLocation()).Rotator(); //Find the rotator required for the turret to face it's target
Tank->BotTurret->SetWorldRotation(FRotator(0.f, Rot.Yaw, 0.f)); //Point the turret to it's target
}
}
}
}
if (BestPawn)
{
SetEnemy(BestPawn); //Once the closest player is found, set the Bot's target
}
}
示例15: TickNode
void UBTService_SearchPlayer::TickNode(UBehaviorTreeComponent &OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
if (!OwnerComp.GetBlackboardComponent())
{
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, "Failed to get Blackboard Component");
return;
}
OwnerComp.GetBlackboardComponent()->SetValueAsObject("Player", (UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)));
if (OwnerComp.GetBlackboardComponent()->GetValueAsEnum("State") == static_cast<uint8>(EState::ES_Combat))
{
APawn* Player = (UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
ALivingEntity* Enemy = nullptr;
AEnemyController* EnemyController = Cast<AEnemyController>(OwnerComp.GetOwner());
if (EnemyController)
{
Enemy = Cast<ALivingEntity>(EnemyController->GetPawn());
}
if (Player && Enemy)
{
if (!CanSeePlayer(Enemy, Player))
{
OwnerComp.GetBlackboardComponent()->SetValueAsEnum("State", static_cast<uint8>(EState::ES_Walking));
}
else
{
EnemyController->UpdateMemoryMarker(Player->GetActorLocation());
}
}
else
{
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Red, "Error whilst casting");
}
}
}