void ATankAIController::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);
	auto aiTank = GetPawn();
	auto playerTank = GetWorld()->GetFirstPlayerController()->GetPawn();
	if (ensure(playerTank)) {

		// TODO Move towards the player
		MoveToActor(playerTank, acceptanceRadius); // TODO check radius is in cm

		// Aim towards the player
		auto aimComponent = aiTank->FindComponentByClass<UTankAimingComponent>();
		aimComponent->AimAt(playerTank->GetActorLocation());
		

		//GetPawn().reloadTimeInSeconds = 10;
		// Fire if ready
		if (aimComponent->GetFiringState() == EFiringStatus::Ready) {
			aimComponent->Fire();
			//UE_LOG(LogTemp,Warning,TEXT("AI Tank Ready and Firing!"))
		}


		
	}

}
Ejemplo n.º 2
0
void ATankAIController::Tick(float deltaTime)
{
	Super::Tick(deltaTime);

	auto playerTank = GetWorld()->GetFirstPlayerController()->GetPawn();

	if (ensure(playerTank && GetPawn()))
	{
		MoveToActor(playerTank, acceptanceRadius);

		auto aimingComponent = GetPawn()->FindComponentByClass<UTankAimingComponent>();
		aimingComponent->AimAt(playerTank->GetActorLocation());

		if(aimingComponent->GetFiringStatus() == EFiringStatus::Locked)
			aimingComponent->Fire();
	}
}
Ejemplo n.º 3
0
// Called every frame
void ATankAIController::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	auto PlayerTank = Cast<ATank>(GetWorld()->GetFirstPlayerController()->GetPawn());
	auto ControlledTank = Cast<ATank>(GetPawn());

	if (PlayerTank)
	{
		// Move towards the player
		MoveToActor(PlayerTank, AcceptanceRadius); // TODO check radius is in cm

		// Aim towards the player
		ControlledTank->AimAt(PlayerTank->GetActorLocation());

		ControlledTank->Fire(); // TODO limit firing rate
	}
}
Ejemplo n.º 4
0
void ABaleroPlayerController::OnRightClickPressed()
{
	UE_LOG(LogTemp, Warning, TEXT("rightclick"));
	FHitResult Hit;
	GetHitResultUnderCursor(ECC_Visibility, false, Hit);
	FVector2D MouseLocation;
	GetMousePosition(MouseLocation.X, MouseLocation.Y);

	int32 ViewportX;
	int32 ViewportY;
	GetViewportSize(ViewportX, ViewportY);

	if (MouseLocation.X > ViewportX * .9f)
	{
		return;
	}


	if (Hit.bBlockingHit)
	{
		UE_LOG(LogTemp, Warning, TEXT("rightclickedsomething"));


		APawn* pawn = Cast<APawn>(Hit.GetActor());
		if (pawn != NULL)
		{
			UE_LOG(LogTemp, Warning, TEXT("clicked pawn"));

			ABaleroCharacter* Unit = Cast<ABaleroCharacter>(pawn);
			if (Unit != NULL)
			{
				MoveToActor(Unit);
			}
		}
		else
		{
			MoveToMouseCursor();
		}
	}


}
Ejemplo n.º 5
0
void ATankAIController::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	auto PlayerTank = GetWorld()->GetFirstPlayerController()->GetPawn();
	auto AITank = GetPawn();

	if (!ensure(PlayerTank && AITank)) { return; }

	auto AIAimComp = AITank->FindComponentByClass<UTankAimingComponent>();
	// Move towards Actor
	MoveToActor(PlayerTank, AcceptanceRadius);
	// Aim towards the player
	AIAimComp->AimAt(PlayerTank->GetActorLocation());

	if (AIAimComp->GetFiringState() == EFiringState::Locked)
	{
		AIAimComp->Fire();
	}
}
Ejemplo n.º 6
0
void ATankAIController::Tick(float DeltaTime){
    
    Super::Tick(DeltaTime);
    
    auto PlayerTank = GetWorld()->GetFirstPlayerController()->GetPawn();
    
    auto ControlledTank = GetPawn();
    
    if(!ensure(PlayerTank && ControlledTank)){return ; }
        
        //move towards player
        MoveToActor(PlayerTank, AcceptanceRadius);
        //aim towards the player
    auto AimingComponent = ControlledTank->FindComponentByClass<UTankAimingComponent>();
        AimingComponent->AimAt(PlayerTank->GetActorLocation());
        //Fire if ready
    if(AimingComponent->GetFiringStatus() == EFiringStatus::Locked)
    {
    AimingComponent->Fire();
    }
}
Ejemplo n.º 7
0
void ATankAIController::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	auto PlayerTank = GetWorld()->GetFirstPlayerController()->GetPawn();
	auto ControlledTank =GetPawn();
	if (!ensure(PlayerTank && ControlledTank)) { return; }
	//Move Towards the player
	MoveToActor(PlayerTank, AcceptanceRadius);

	//aim towards the player
	auto AimingComponent = ControlledTank->FindComponentByClass<UTankAimingComponent>();
	AimingComponent->AimAt(PlayerTank->GetActorLocation());
		
	//if aiming or locked
	if (AimingComponent->GetFiringState() == EFiringState::Locked)
	{
		AimingComponent->Fire(); //TODO dont fire every frame , limit fire rate
	}
	
}