Skip to content

Commit

Permalink
BT76 Aiming Without the Tank.cmproj
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Tristem committed Jul 15, 2016
1 parent bc5d8ec commit 3284906
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 41 deletions.
Binary file modified BattleTank/Content/Tank/Tank_BP.uasset
Binary file not shown.
Binary file modified BattleTank/Content/_Levels/BattleGround.umap
Binary file not shown.
8 changes: 0 additions & 8 deletions BattleTank/Source/BattleTank/Private/Tank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include "BattleTank.h"
#include "TankBarrel.h"
#include "Projectile.h"
#include "TankAimingComponent.h"
#include "Tank.h"


Expand All @@ -17,13 +16,6 @@ ATank::ATank()
void ATank::BeginPlay()
{
Super::BeginPlay(); // Needed for BP Begin Play to run!
TankAimingComponent = FindComponentByClass<UTankAimingComponent>();
}

void ATank::AimAt(FVector HitLocation)
{
if (!ensure(TankAimingComponent)) { return; }
TankAimingComponent->AimAt(HitLocation, LaunchSpeed);
}

void ATank::Fire()
Expand Down
24 changes: 13 additions & 11 deletions BattleTank/Source/BattleTank/Private/TankAIController.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Fill out your copyright notice in the Description page of Project Settings.

#include "BattleTank.h"
#include "Tank.h"
#include "TankAimingComponent.h"
#include "TankAIController.h"
// Depends on movement component via pathfinding system

Expand All @@ -15,17 +15,19 @@ void ATankAIController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

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

if (ensure(PlayerTank))
{
// Move towards the player
MoveToActor(PlayerTank, AcceptanceRadius); // TODO check radius is in cm
if (!ensure(PlayerTank && ControlledTank)) { return; }

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

// Aim towards the player
ControlledTank->AimAt(PlayerTank->GetActorLocation());
// Aim towards the player
auto AimingComponent = ControlledTank->FindComponentByClass<UTankAimingComponent>();
AimingComponent->AimAt(PlayerTank->GetActorLocation());

ControlledTank->Fire(); // TODO limit firing rate
}
// TODO fix firing
// ControlledTank->Fire(); // TODO limit firing rate

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void UTankAimingComponent::Initialise(UTankBarrel* BarrelToSet, UTankTurret* Tur
Turret = TurretToSet;
}

void UTankAimingComponent::AimAt(FVector HitLocation, float LaunchSpeed)
void UTankAimingComponent::AimAt(FVector HitLocation)
{
if (!ensure(Barrel)) { return; }

Expand Down
13 changes: 4 additions & 9 deletions BattleTank/Source/BattleTank/Private/TankPlayerController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

#include "BattleTank.h"
#include "TankAimingComponent.h"
#include "Tank.h"
#include "TankPlayerController.h"


void ATankPlayerController::BeginPlay()
{
Super::BeginPlay();
auto AimingComponent = GetControlledTank()->FindComponentByClass<UTankAimingComponent>();
auto AimingComponent = GetPawn()->FindComponentByClass<UTankAimingComponent>();
if (!ensure(AimingComponent)) { return; }
FoundAimingComponent(AimingComponent);
}
Expand All @@ -20,19 +19,15 @@ void ATankPlayerController::Tick(float DeltaTime)
AimTowardsCrosshair();
}

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

void ATankPlayerController::AimTowardsCrosshair()
{
if (!ensure(GetControlledTank())) { return; }
auto AimingComponent = GetPawn()->FindComponentByClass<UTankAimingComponent>();
if (!ensure(AimingComponent)) { return; }

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

Expand Down
7 changes: 0 additions & 7 deletions BattleTank/Source/BattleTank/Public/Tank.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

// Forward declarations
class UTankBarrel;
class UTankAimingComponent;
class AProjectile;

UCLASS()
Expand All @@ -16,15 +15,9 @@ class BATTLETANK_API ATank : public APawn
GENERATED_BODY()

public:
void AimAt(FVector HitLocation);

UFUNCTION(BlueprintCallable, Category = "Firing")
void Fire();

protected:
UPROPERTY(BlueprintReadOnly)
UTankAimingComponent* TankAimingComponent = nullptr;

private:
// Sets default values for this pawn's properties
ATank();
Expand Down
5 changes: 4 additions & 1 deletion BattleTank/Source/BattleTank/Public/TankAimingComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BATTLETANK_API UTankAimingComponent : public UActorComponent
UFUNCTION(BlueprintCallable, Category = "Setup")
void Initialise(UTankBarrel* BarrelToSet, UTankTurret* TurretToSet);

void AimAt(FVector HitLocation, float LaunchSpeed);
void AimAt(FVector HitLocation);

protected:
UPROPERTY(BlueprintReadOnly, Category = "State")
Expand All @@ -40,6 +40,9 @@ class BATTLETANK_API UTankAimingComponent : public UActorComponent

UTankBarrel* Barrel = nullptr;
UTankTurret* Turret = nullptr;

UPROPERTY(EditDefaultsOnly, Category = "Firing")
float LaunchSpeed = 4000;

void MoveBarrelTowards(FVector AimDirection);
};
4 changes: 0 additions & 4 deletions BattleTank/Source/BattleTank/Public/TankPlayerController.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "GameFramework/PlayerController.h"
#include "TankPlayerController.generated.h" // Must be the last include

class ATank;
class UTankTankAimingComponent;

/**
Expand All @@ -17,9 +16,6 @@ class BATTLETANK_API ATankPlayerController : public APlayerController
GENERATED_BODY()

protected:
UFUNCTION(BlueprintCallable, Category = "Setup")
ATank* GetControlledTank() const;

UFUNCTION(BlueprintImplementableEvent, Category = "Setup")
void FoundAimingComponent(UTankAimingComponent* AimCompRef);

Expand Down

0 comments on commit 3284906

Please sign in to comment.