No player location logged out

I am not to sure if i have missed a #include in the tankplayercontroller cpp file but i am unable to log out were my player tank is and the AI tanks are unable to locate were i am in the world. The AI tanks cal log out were they are in the world but not the player. i have attached a copy of my code to see if anyone can help. Windows 10, VS 2017, UE4.19

AI%20log%20out

code

I doubt you are missing a header file include if you are compiling successfully. Perhaps it is the way you are logging out the values themselves. Mind sharing your code for the actual log statement?

sorry i really do not know how to put this kind of thin up online

// Fill out your copyright notice in the Description page of Project Settings.

#include “TankPlayerController.h”
#include “GameFramework/Actor.h”
#include “GameFramework/Pawn.h”
#include “Engine/World.h”
#include “GameFramework/Controller.h”

void ATankPlayerController::BeginPlay()
{
Super::BeginPlay();

auto ControlledTank = GetControlledTank();
if (!ControlledTank)
{
	UE_LOG(LogTemp, Warning, TEXT("PlayerController Begin Play"));
}
else
{
	UE_LOG(LogTemp, Warning, TEXT("PlayerController possessing: %s"), *(ControlledTank->GetName()))
}

}

ATank * ATankPlayerController::GetControlledTank() const {
return Cast(GetPawn());
};

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

FVector HitLocation;
if (GetSightRayHitLocation(HitLocation))
{
	GetControlledTank()->AImAt(HitLocation);
}

}

// Called every frame
void ATankPlayerController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
AimTowardsCrosshair();
}

bool ATankPlayerController::GetSightRayHitLocation(FVector& HitLocation) const
{
//Find the crosshair position in pixels coordinates
int32 ViewPortSizeX, ViewPortSizeY;
GetViewportSize(ViewPortSizeX, ViewPortSizeY);
auto ScreenLocation = FVector2D(ViewPortSizeX * CrossHairXLocation, ViewPortSizeY * CrossHairYLocation);
FVector LookDirection;
if (GetLookDirection(ScreenLocation, LookDirection))
{
GetLookVectorHitLocation(LookDirection, HitLocation);
}

return false;

}

bool ATankPlayerController::GetLookDirection(FVector2D ScreenLocation, FVector& LookDirection) const
{
FVector CameraWorldLocation;
return DeprojectScreenPositionToWorld(ScreenLocation.X, ScreenLocation.Y, CameraWorldLocation, LookDirection);

}

bool ATankPlayerController::GetLookVectorHitLocation(FVector LookDirection, FVector&HitLocation) const
{
FHitResult HitResult;
auto StartLocation = PlayerCameraManager->GetCameraLocation();
auto EndLocation = StartLocation + (LookDirection * LineTraceRange);
if (GetWorld()->LineTraceSingleByChannel(HitResult, StartLocation, EndLocation, ECollisionChannel::ECC_Visibility))
{
HitLocation = HitResult.Location;
return true;
}
HitLocation = FVector(0);
return false;
}

Hmm, still not seeing the UE_LOG statement that would produce the output you put in your first post. Also, you should be able to wrap all of the code in a preformatted text brackets and it will display as formatted C++.

from what the video says the UE_LOG was moved into the TankAimingCommonent cpp file. it logs out ok, it just is not saying were the player controlled tank is located

// Fill out your copyright notice in the Description page of Project Settings.

  #include "TankAimingComponent.h"
  #include "GameFramework/Actor.h"


    // Sets default values for this component's properties
  UTankAimingComponent::UTankAimingComponent()
  {
// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn                   these features
// off to improve performance if you don't need them.
PrimaryComponentTick.bCanEverTick = true;

// ...
  }


  // Called when the game starts
  void UTankAimingComponent::BeginPlay()
  {
Super::BeginPlay();

// ...

  }


  void UTankAimingComponent::AimAt(FVector HitLocation, float LaunchSpeed)
  {if (!Barrel)
  {
return;
  }
FVector OutLaunchVelocity;
FVector StartLocation = Barrel->GetSocketLocation(FName("Projectile"));

auto AimDirection = OutLaunchVelocity.GetSafeNormal();
UE_LOG(LogTemp, Warning, TEXT("Aiming at %s"), *AimDirection.ToString());
  }

  void UTankAimingComponent::SetBarrelReference(UStaticMeshComponent * BarrelToSet)
  {
Barrel = BarrelToSet;
  }

  // Called every frame
  void UTankAimingComponent::TickComponent(float DeltaTime, ELevelTick TickType,             FActorComponentTickFunction* ThisTickFunction)
  {
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

// ...
  }

indent preformatted text by 4 spaces

Ah, now I see the issue. Essentially your code is passing an uninitialized value for OutLaunchVelocity to the log. You are missing a call to SuggestProjectileVelocity, which sets the value of OutLaunchVelocity:

if (UGameplayStatics::SuggestProjectileVelocity
(
	this,
	OutLaunchVelocity,
	StartLocation,
	HitLocation,
	LaunchSpeed,
	false,
	0,
	0,
	ESuggestProjVelocityTraceOption::DoNotTrace
))
{
    auto AimDirection = OutLaunchVelocity.GetSafeNormal();
    UE_LOG(LogTemp, Warning, TEXT("Aiming at %s"), *AimDirection.ToString());
}

Refer back to the lecture around the point of the bookmark to see the implementation and explanation.

Privacy & Terms