Commit 47896a80 authored by Ridel Morgan's avatar Ridel Morgan
Browse files

update

parent 9954c11e
......@@ -7,7 +7,11 @@
{
"Name": "BattleTanks",
"Type": "Runtime",
"LoadingPhase": "Default"
"LoadingPhase": "Default",
"AdditionalDependencies": [
"Engine",
"AIModule"
]
}
]
}
\ No newline at end of file
......@@ -8,7 +8,7 @@ AppliedDefaultGraphicsPerformance=Maximum
[/Script/EngineSettings.GameMapsSettings]
EditorStartupMap=/Game/Battleground.Battleground
GameDefaultMap=/Game/Battleground.Battleground
GameDefaultMap=/Game/MainMenu.MainMenu
GlobalDefaultGameMode=/Game/BattleTanksGameMode_BP.BattleTanksGameMode_BP_C
[/Script/Engine.PhysicsSettings]
......@@ -52,4 +52,3 @@ AsyncSceneSmoothingFactor=0.990000
InitialAverageFrameRate=0.016667
PhysXTreeRebuildRate=10
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
// Fill out your copyright notice in the Description page of Project Settings.
#include "Tank.h"
// Sets default values
ATank::ATank()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
TankAimingComponent = CreateDefaultSubobject<UTankAimingComponent>(FName("Aiming Component"));
}
void ATank::AimAt(FVector HitLocation)
{
TankAimingComponent->AimAt(HitLocation);
}
// Called when the game starts or when spawned
void ATank::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ATank::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void ATank::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
// Fill out your copyright notice in the Description page of Project Settings.
#include "TankAIController.h"
#include "Engine/World.h"
ATank* ATankAIController::GetControlledTank() const
{
return Cast<ATank>(GetPawn());
}
void ATankAIController::BeginPlay()
{
Super::BeginPlay();
ATank* PlayerTank = GetPlayerTank();
if (PlayerTank)
{
UE_LOG(LogTemp, Warning, TEXT("Player Tank located by AI : %s"), *PlayerTank->GetName());
}
}
ATank * ATankAIController::GetPlayerTank() const
{
APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
if (PlayerController)
{
return Cast<ATank>(PlayerController->GetPawn());
}
else
{
return nullptr;
}
}
void ATankAIController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (!GetControlledTank()) { return; }
if (GetPlayerTank())
{
GetControlledTank()->AimAt(GetPlayerTank()->GetActorLocation());
}
}
// 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();
// ...
}
// Called every frame
void UTankAimingComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
// ...
}
void UTankAimingComponent::AimAt(FVector HitLocation)
{
UE_LOG(LogTemp, Warning, TEXT("%s aiming at %s"), *GetOwner()->GetName(), *HitLocation.ToString())
}
// Fill out your copyright notice in the Description page of Project Settings.
#include "TankPlayerController.h"
#include "Engine/World.h"
#include "DrawDebugHelpers.h"
ATank* ATankPlayerController::GetControlledTank() const
{
return Cast<ATank>(GetPawn());
}
void ATankPlayerController::BeginPlay()
{
Super::BeginPlay();
ATank* ControlledTank = GetControlledTank();
if (ControlledTank)
{
UE_LOG(LogTemp, Warning, TEXT("Tank controlled : %s"), *ControlledTank->GetName());
}
}
void ATankPlayerController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
AimTowardsCrosshair();
}
void ATankPlayerController::AimTowardsCrosshair()
{
if (!GetControlledTank()) { return; }
FVector HitLocation;
if (GetSightRayHitLocation(HitLocation))
{
GetControlledTank()->AimAt(HitLocation);
}
}
bool ATankPlayerController::GetSightRayHitLocation(FVector & HitLocation) const
{
int32 ViewportSizeX, ViewportSizeY;
GetViewportSize(ViewportSizeX, ViewportSizeY);
FVector2D ScreenLocation = FVector2D(ViewportSizeX * CrosshairXLocation, ViewportSizeY * CrossHairYLocation);
FVector LookDirection;
if (GetLookDirection(ScreenLocation, LookDirection))
{
if (GetLookVectorHitLocation(LookDirection, HitLocation))
{
return true;
}
}
return false;
}
bool ATankPlayerController::GetLookDirection(FVector2D ScreenLocation, FVector& LookDirection) const
{
FVector WorldLocation;
return DeprojectScreenPositionToWorld(ScreenLocation.X, ScreenLocation.Y, WorldLocation, LookDirection);
}
bool ATankPlayerController::GetLookVectorHitLocation(FVector LookDirection, FVector & HitLocation) const
{
FHitResult HitResult;
FVector StartLocation = PlayerCameraManager->GetCameraLocation();
FVector EndLocation = StartLocation + (LookDirection * LineTraceRange);
if (GetWorld()->LineTraceSingleByChannel(HitResult, StartLocation, EndLocation, ECollisionChannel::ECC_Visibility))
{
HitLocation = HitResult.Location;
return true;
}
HitLocation = FVector(0);
return false;
}
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "TankAimingComponent.h"
#include "GameFramework/Pawn.h"
#include "Tank.generated.h"
UCLASS()
class BATTLETANKS_API ATank : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
ATank();
void AimAt(FVector HitLocation);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
UTankAimingComponent* TankAimingComponent = nullptr;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
};
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "AIController.h"
#include "Tank.h"
#include "TankAIController.generated.h"
/**
*
*/
UCLASS()
class BATTLETANKS_API ATankAIController : public AAIController
{
GENERATED_BODY()
public:
ATank* GetControlledTank() const;
virtual void BeginPlay() override;
ATank* GetPlayerTank() const;
virtual void Tick(float DeltaTime) override;
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment