Exemplo n.º 1
0
/**
 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);
        
    }
}
Exemplo n.º 2
0
//A function to determine if the found enemy is within the line-of-sight of the bot
bool ABotController::PawnCanBeSeen(APawn* target)
{
	if (target == NULL || GetPawn() == NULL)
	{
		return false;
	}
	FVector difference = target->GetActorLocation() - GetPawn()->GetActorLocation();
	float angle = FVector::DotProduct(difference, GetPawn()->GetActorRotation().Vector());

	//LineOfSightTo determines if the bot can see the actor in the direction it's facing
	if (LineOfSightTo(target, GetPawn()->GetActorLocation()) && angle >0)
	{
		return true;
	}
	else
	{
		return false;
	}
}
Exemplo n.º 3
0
void AFournoidAIController::ShootEnemy(){
	AEnemyCharacter* MyBot = Cast<AEnemyCharacter>(GetPawn());
	//AShooterWeapon* MyWeapon = MyBot ? MyBot->GetWeapon() : NULL;
	
	bool bCanShoot = false;
	AFournoidCharacter* Enemy = GetEnemy();
	if ( MyBot->IsAlive() && Enemy && ( Enemy->IsAlive() ))
	{
		if (LineOfSightTo(Enemy, MyBot->GetActorLocation()))
		{
			bCanShoot = true;
		}
	}
	
	if (bCanShoot)
	{
		MyBot->StartFire();
	}
	else
	{
		MyBot->StopFire();
	}
}