void ATankPlayerController::AimTowardsCrosshair()
{
	if (!GetControlledTank()) return;

	FVector HitLocation;

	if (GetSightRayHitLocation(HitLocation)) {
		GetControlledTank()->AimAt(HitLocation);
	}
		
}
void ATankPlayerController::AimTowardsCrosshair()
{
	if (!GetControlledTank()) { return; }	

	FVector HitLocation;
	if (GetSightRayHitLocation(HitLocation))
	{
		GetControlledTank()->AimAt(HitLocation);
	}
	
	// If it hits the landscape
	// Tell conctrolled tank to aim at this point
}
void ATankPlayerController::AimTowardsCrosshair()
{
	if (!GetControlledTank()) { return; }

	FVector HitLocation; // Out parameter
	if (GetSightRayHitLocation(HitLocation)) 
	{ 
		GetControlledTank()->AimAt(HitLocation);
		return; 
	}
	// Has "side-effect", is going to line trace

	// Get world location of linetrace through crosshair
	// If it hits the landscape
		// Tell the controlled tank to aim at this point
}
void ATankAIController::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	if (GetPlayerTank())
	{
		GetControlledTank()->AimAt(GetPlayerTank()->GetActorLocation());
	}
}
void ATankAIController::Tick(float deltaTime) {
	Super::Tick(deltaTime);

	ATank* PlayerTank = GetPlayerTank();

	if (PlayerTank) {
		GetControlledTank()->AimAt(PlayerTank->GetActorLocation());
	}
}
void ATankPlayerController::AimTowardsCrosshair()
{
	if (!GetControlledTank()) { return; }
	FVector HitLocation;
	
	if (GetSightRayHitLocation(HitLocation))
	{
		GetControlledTank()->AimAt(HitLocation);
	}
	else 
	{
		//UE_LOG(LogTemp, Warning, TEXT("No hit found"));
	}
	//raycast to world
	//if it hits the landscape, aim at the point of intersection

	//UE_LOG(LogTemp, Warning, TEXT("PlayerController AimTowardsCrosshair()"));
}
void ATankAIController::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	//UE_LOG(LogTemp, Warning, TEXT("TEST"));

	if (GetPlayerTank())
	{
		// TODO move towards the player
		// aim towards player
		GetControlledTank()->AimAt(GetPlayerTank()->GetActorLocation());
		// fire if ready

	}
}
void ATankPlayerController::BeginPlay()
{
	Super::BeginPlay();
	auto ControlledTank = GetControlledTank();

	if (!ControlledTank)
	{
		UE_LOG(LogTemp, Warning, TEXT("PlayController not posessing a tank"));
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("PlayController posessing %s"), *ControlledTank->GetName());
	}	
}
void ATankPlayerController::BeginPlay()
{
    Super::BeginPlay();
    
    auto ControlledTank = GetControlledTank();
    
    if (!ControlledTank) {
        UE_LOG(LogTemp, Warning, TEXT("Tank Controlled: None"));
    }
    else
    {
        UE_LOG(LogTemp, Warning, TEXT("Tank Controlled: %s"), *(ControlledTank->GetName()));
    }
}
Esempio n. 10
0
void ATankAIController::BeginPlay()
{
	Super::BeginPlay();
	auto PlayerTank = GetPlayerTank();
	auto ControllerTank = GetControlledTank();
	if (!PlayerTank)
	{
		UE_LOG(LogTemp, Warning, TEXT("AIController Cant Find Player Tank"));
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("AIController found player: %s"), *(ControllerTank->GetName()));
	}
	
	
}
void ATankAIController::BeginPlay()
{
	Super::BeginPlay();

	auto ControlledTank = GetControlledTank();

	auto PlayerTank = GetPlayerTank();
	if (!PlayerTank)
	{
		UE_LOG(LogTemp, Warning, TEXT("AI(%s): Player not found..."), *ControlledTank->GetName());
	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("AI(%s): Player %s found"),*ControlledTank->GetName(), *PlayerTank->GetName());
	}
}
bool ATankPlayerController::LineTrace(FVector Start, FVector Direction, TArray<FHitResult> &HitResults) const
{
	FVector End = Start + Direction * RayCastDistance;
	FCollisionQueryParams RV_TraceParams = FCollisionQueryParams(FName(TEXT("RV_Trace")), true, this);
	RV_TraceParams.bTraceComplex = true;
	RV_TraceParams.bTraceAsyncScene = true;
	RV_TraceParams.bReturnPhysicalMaterial = true;
	RV_TraceParams.AddIgnoredActor(GetControlledTank());
	
	//do the line trace
	return GetWorld()->LineTraceMultiByChannel(
		HitResults,        //result
		Start,        //start
		End,        //end
		ECC_Visibility,    //collision channel
		RV_TraceParams
	);
}
bool ATankPlayerController::GetSightRayHitLocation(FVector& HitLocation) const
{
	FVector2D CrosshairLocation;
	GetCrosshairScreenLocation(CrosshairLocation);
	
	FVector WorldLocation;
	FVector WorldDirection;

	if (DeprojectScreenPositionToWorld(CrosshairLocation.X, CrosshairLocation.Y, WorldLocation, WorldDirection)) {
		//UE_LOG(LogTemp, Warning, TEXT("World location: %s World direction: %s"), *WorldLocation.ToString(), *WorldDirection.ToString());
	}
	
	TArray<FHitResult> HitResults = TArray<FHitResult>();
	
	if (LineTrace(WorldLocation, WorldDirection, HitResults)) {
		bool aimingThroughPlayer = false;
		for (int i = 0; i < HitResults.Num(); i++) {
			FHitResult HitResult = HitResults[i];
			if (HitResult.IsValidBlockingHit()) {
				if (HitResult.GetActor() != GetControlledTank()) {
					if (aimingThroughPlayer)
					{
						UE_LOG(LogTemp, Warning, TEXT("Aiming through player tank actor, next hit is: %s"), *HitResult.ImpactPoint.ToString());
					}

					HitLocation = HitResult.ImpactPoint;
					return true;
				}else
				{
					aimingThroughPlayer = true;
					UE_LOG(LogTemp, Warning, TEXT("%i hits, aiming through player tank actor: %s"),HitResults.Num(), *HitResult.ImpactPoint.ToString());
				}
			}
			else
			{
				HitLocation = FVector(0);
				return false;
			}
		}
		
	}

	return false;
}
void ATankAIController::BeginPlay() {
	Super::BeginPlay();

	ATank* ThisTank = GetControlledTank();

	if (!ThisTank)
	{
		GEngine->AddOnScreenDebugMessage(-1, 20.f, FColor::Red, TEXT("[TAIC] AI Tank not found"));
	}

	ATank* PlayerTank = GetPlayerTank();

	if (PlayerTank) {
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, FString::Printf(TEXT("[TAIC] Player Tank %s found!"), *PlayerTank->GetName()));
	}
	else
	{
		GEngine->AddOnScreenDebugMessage(-1, 20.f, FColor::Red, TEXT("[TAIC] Player Tank not found"));
	}
}
void ATankPlayerController::BeginPlay()
{
	Super::BeginPlay();
	//UE_LOG(LogTemp, Warning, TEXT("PlayerController Begin Play"));
	auto ControlledTank = GetControlledTank();
}