引用c++ue4中的当兵玩家

Referencing pawn player in c++ ue4

本文关键字:玩家 c++ue4 引用      更新时间:2023-10-16

对于一个项目,我正在设计一个坦克游戏,希望坦克能一直盯着我的玩家,但在网上看了很多之后,我还没有找到在c++中引用我的玩家的解决方案

 ATank* myCharacter = Cast<ATank>(this);
     if (myCharacter)
     {
         FVector targetLocation = myCharacter->GetActorLocation();
         FVector myLocation = GetActorLocation();
         FRotator newrot = (myLocation -targetLocation).Rotation();
         NewRotation.Yaw = newrot.Yaw;
         SetActorRotation(NewRotation);
     }

以上是我目前所拥有的一切,因为它没有找到球员,在我发表if声明之前,它只是崩溃了,任何帮助/指导都是感谢和感谢的。

您可以使用UGameplayStatics::GetPlayerPawn(...) UE文档,每个ATank都可以保存它对您的典当的引用。然后,您应该检查存储的引用是否为null,并检查IsValidLowLevel()。下一步是使用玩家典当参考执行所需的计算。