EDIT: solved! Forgotten to add AimTowardsCrosshair(); in ATankPlayerController::Tick
I got the problem since previous lesson. Logs are not working in ATankPlayerController::GetSightRayHitLocation. No matter what I put there, even simple text.
This is how my code looks now:
TankPlayerController.cpp
#include “TankPlayerController.h”
void ATankPlayerController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
//UE_LOG(LogTemp, Warning, TEXT("Player Controller is ticking"));
}
void ATankPlayerController::BeginPlay()
{
Super::BeginPlay();
auto ControlledTank = GetControlledTank();
if (!ControlledTank)
{
UE_LOG(LogTemp, Warning, TEXT("Player Controller not possesing a tank"));
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Player Controller possesing: %s"), *(ControlledTank->GetName()));
}
}
ATank* ATankPlayerController::GetControlledTank() const
{
return Cast<ATank>(GetPawn());
}
void ATankPlayerController::AimTowardsCrosshair()
{
if (!GetControlledTank()) { return; }
FVector HitLocation;
if (GetSightRayHitLocation(HitLocation))
{
//UE_LOG(LogTemp, Warning, TEXT("Look direction: %s"), *HitLocation.ToString());
}
}
bool ATankPlayerController::GetSightRayHitLocation(FVector& OutHitLocation) const
{
int32 ViewportSizeX, ViewportSizeY;
GetViewportSize(ViewportSizeX, ViewportSizeY);
auto ScreenLocation = FVector2D(ViewportSizeX * CrosshairXLocation, ViewportSizeY * CrosshairYLocation);
UE_LOG(LogTemp, Warning, TEXT("ScreenLocation: %s"), *ScreenLocation.ToString());
return true;
}
TankPlayerController.h
#pragma once
#include "CoreMinimal.h"
#include "Tank.h"
#include "GameFramework/PlayerController.h"
#include "TankPlayerController.generated.h"
/**
*
*/
UCLASS()
class BATTLETANK_API ATankPlayerController : public APlayerController
{
GENERATED_BODY()
public:
virtual void BeginPlay() override;
virtual void Tick(float DeltaTime) override;
private:
ATank* GetControlledTank() const;
void AimTowardsCrosshair();
bool GetSightRayHitLocation(FVector& OutHitLocation) const;
UPROPERTY(EditAnywhere)
float CrosshairXLocation = 0.5;
UPROPERTY(EditAnywhere)
float CrosshairYLocation = 0.3333;
};