Download

UE4 AI??-shooterGame??AI??

@???
@2014.3.29
???ShooterAIController.cpp???,???.
???bot?,???bot???,?UE4??Controller??APawn?,???UE3???.???Possess???,???].???:
AShooterAIController::AShooterAIController(constclass FPostConstructInitializeProperties& PCIP) : Super(PCIP)
{
BlackboardComp= PCIP.CreateDefaultSubobject<UBlackboardComponent>(this, TEXT(“BlackBoardComp”));
BehaviorComp= PCIP.CreateDefaultSubobject<UBehaviorTreeComponent>(this, TEXT(“BehaviorComp”));
bWantsPlayerState= true;
}
???,???.??,???,???”?”??.
void AShooterAIController::Possess(APawnInPawn)
{
Super::Possess(InPawn);
AShooterBot
Bot = Cast<AShooterBot>(InPawn);
//start behavior
if(Bot && Bot->BotBehavior)
{
BlackboardComp->InitializeBlackboard(Bot->BotBehavior->BlackboardAsset);
EnemyKeyID= BlackboardComp->GetKeyID(“Enemy”);
NeedAmmoKeyID= BlackboardComp->GetKeyID(“NeedAmmo”);
BehaviorComp->StartTree(Bot->BotBehavior);
}
}
???possess??,???,???.
Bot ? Bot->BotBehavior,Bot??NPC???, Bot->BotBehavior???,???,???.
class AShooterBot : public AShooterCharacter
{
GENERATED_UCLASS_BODY()
UPROPERTY(EditAnywhere,Category=Behavior)
classUBehaviorTree* BotBehavior;
virtualbool IsFirstPerson() const OVERRIDE;
virtualvoid FaceRotation(FRotator NewRotation, float DeltaTime = 0.f) OVERRIDE;
};
???:

http://xiangce.baidu.com/picture/detail/e37108dc59e9f34ba5b774b8eccf7fd6de2a907b?from=dialog

???,???,???.

???,???,???,???Map,???,??UE4???,???.???.???.

http://xiangce.baidu.com/picture/detail/3b0e4f32ab359f07af7203a9a34ec7188b4ce67b?from=dialog

??,???,???.
void AShooterAIController::CheckAmmo(constclass AShooterWeapon* CurrentWeapon)
{
……
BlackboardComp->SetValueAsBool(NeedAmmoKeyID,(Ratio <= 0.1f));
}
void AShooterAIController::SetEnemy(classAPawn* InPawn)
{

BlackboardComp->SetValueAsObject(EnemyKeyID,InPawn);
}
class AShooterCharacter* AShooterAIController::GetEnemy()const
{

returnCast<AShooterCharacter>(BlackboardComp->GetValueAsObject(EnemyKeyID));
}
??,???NPC???,???UE3?FSM.???Tick???,???.

that’s all,thank you!

and what is the problem ? and what is all this “???” I assume it is code comments in Chinese !

void AShooterAIController::Possess(APawn*InPawn)

{

     Super::Possess(InPawn);

     AShooterBot*Bot = Cast&lt;AShooterBot&gt;(InPawn);

     //start behavior

     if(Bot && Bot-&gt;BotBehavior)

     {

               BlackboardComp-&gt;InitializeBlackboard(Bot-&gt;BotBehavior-&gt;BlackboardAsset);

               EnemyKeyID= BlackboardComp-&gt;GetKeyID("Enemy");

               NeedAmmoKeyID= BlackboardComp-&gt;GetKeyID("NeedAmmo");

               BehaviorComp-&gt;StartTree(Bot-&gt;BotBehavior);

     }

}

this is UE4 c++ code AIcontoller Possess (this code is in shootergame project)
this AI is normal untill UE4.6
when I upgrade to 4.6 , compile error

this code have error
BehaviorComp->StartTree(Bot->BotBehavior);

any one know how to fix it?