Debugging Fire / Added Turning / Added rotation to tank and turrets
This commit is contained in:
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,8 +1,9 @@
|
|||||||
// Fill out your copyright notice in the Description page of Project Settings.
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
#include "Components/CapsuleComponent.h"
|
|
||||||
#include "BasePawn.h"
|
#include "BasePawn.h"
|
||||||
|
#include "Components/CapsuleComponent.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
// Sets default values
|
// Sets default values
|
||||||
ABasePawn::ABasePawn()
|
ABasePawn::ABasePawn()
|
||||||
@@ -24,20 +25,40 @@ ABasePawn::ABasePawn()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the game starts or when spawned
|
void ABasePawn::RotateTurret(FVector LookAtTarget)
|
||||||
void ABasePawn::BeginPlay()
|
|
||||||
{
|
{
|
||||||
Super::BeginPlay();
|
FVector ToTarget = LookAtTarget - TurretMesh->GetComponentLocation();
|
||||||
|
FRotator LookAtRotation = FRotator(0.f, ToTarget.Rotation().Yaw, 0.f);
|
||||||
|
TurretMesh->SetWorldRotation(
|
||||||
|
FMath::RInterpTo(
|
||||||
|
TurretMesh->GetComponentRotation(),
|
||||||
|
LookAtRotation,
|
||||||
|
UGameplayStatics::GetWorldDeltaSeconds(this),
|
||||||
|
25.f));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ABasePawn::Fire()
|
||||||
|
{
|
||||||
|
FVector ProjectileSpawnPointLocation = ProjectileSpawnPoint->GetComponentLocation();
|
||||||
|
|
||||||
|
DrawDebugSphere(
|
||||||
|
GetWorld(),
|
||||||
|
ProjectileSpawnPointLocation,
|
||||||
|
25.f,
|
||||||
|
12,
|
||||||
|
FColor::Red,
|
||||||
|
false,
|
||||||
|
3.f);
|
||||||
|
}
|
||||||
|
|
||||||
// Called every frame
|
// Called every frame
|
||||||
void ABasePawn::Tick(float DeltaTime)
|
/*void ABasePawn::Tick(float DeltaTime)
|
||||||
{
|
{
|
||||||
Super::Tick(DeltaTime);
|
Super::Tick(DeltaTime);
|
||||||
|
|
||||||
/*FVector DeltaLocation(0.f);
|
/*FVector DeltaLocation(0.f);
|
||||||
DeltaLocation.X = 2.f;
|
DeltaLocation.X = 2.f;
|
||||||
AddActorLocalOffset(DeltaLocation);*/
|
AddActorLocalOffset(DeltaLocation);
|
||||||
|
|
||||||
}
|
}*/
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ public:
|
|||||||
UPROPERTY(EditInstanceOnly)
|
UPROPERTY(EditInstanceOnly)
|
||||||
int32 EditInstanceOnlyInt = 14;
|
int32 EditInstanceOnlyInt = 14;
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called when the game starts or when spawned
|
|
||||||
virtual void BeginPlay() override;
|
void RotateTurret(FVector LookAtTarget);
|
||||||
|
void Fire();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@@ -57,8 +57,4 @@ private:
|
|||||||
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Super Duper Variables", meta = (AllowPrivateAccess = "true"))
|
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Super Duper Variables", meta = (AllowPrivateAccess = "true"))
|
||||||
int32 VisibleAnywhere = 12;
|
int32 VisibleAnywhere = 12;
|
||||||
|
|
||||||
public:
|
|
||||||
// Called every frame
|
|
||||||
virtual void Tick(float DeltaTime) override;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "Camera/CameraComponent.h"
|
#include "Camera/CameraComponent.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
#include "Components/InputComponent.h"
|
#include "Components/InputComponent.h"
|
||||||
|
#include "DrawDebugHelpers.h"
|
||||||
|
|
||||||
ATank::ATank()
|
ATank::ATank()
|
||||||
{
|
{
|
||||||
@@ -26,9 +27,54 @@ void ATank::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
|||||||
PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &ATank::Move);
|
PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &ATank::Move);
|
||||||
PlayerInputComponent->BindAxis(TEXT("Turn"), this, &ATank::Turn);
|
PlayerInputComponent->BindAxis(TEXT("Turn"), this, &ATank::Turn);
|
||||||
|
|
||||||
|
PlayerInputComponent->BindAction(TEXT("Fire"), IE_Pressed, this, &ATank::Fire);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ATank::Tick(float DeltaTime)
|
||||||
|
{
|
||||||
|
Super::Tick(DeltaTime);
|
||||||
|
|
||||||
|
if (PlayerControllerRef)
|
||||||
|
{
|
||||||
|
FHitResult HitResult;
|
||||||
|
PlayerControllerRef->GetHitResultUnderCursor(
|
||||||
|
ECollisionChannel::ECC_Visibility,
|
||||||
|
false,
|
||||||
|
HitResult);
|
||||||
|
|
||||||
|
RotateTurret(HitResult.ImpactPoint);
|
||||||
|
|
||||||
|
/*DrawDebugSphere(
|
||||||
|
GetWorld(),
|
||||||
|
HitResult.ImpactPoint,
|
||||||
|
25.f,
|
||||||
|
12,
|
||||||
|
FColor::Red,
|
||||||
|
false,
|
||||||
|
-1.f);*/
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Called when the game starts or when spawned
|
||||||
|
void ATank::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
PlayerControllerRef = Cast<APlayerController>(GetController());
|
||||||
|
/*
|
||||||
|
DrawDebugSphere(
|
||||||
|
GetWorld(),
|
||||||
|
GetActorLocation() + FVector(0.f, 0.f, 200.f),
|
||||||
|
100.f,
|
||||||
|
12,
|
||||||
|
FColor::Red,
|
||||||
|
true,
|
||||||
|
30.f);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
void ATank::Move(float Value)
|
void ATank::Move(float Value)
|
||||||
{
|
{
|
||||||
//FVector DeltaLocation(0.f); //Same as line below
|
//FVector DeltaLocation(0.f); //Same as line below
|
||||||
@@ -42,5 +88,8 @@ void ATank::Move(float Value)
|
|||||||
void ATank::Turn(float TValue)
|
void ATank::Turn(float TValue)
|
||||||
{
|
{
|
||||||
//UE_LOG(LogTemp, Warning, TEXT("Value: %f"), TValue);
|
//UE_LOG(LogTemp, Warning, TEXT("Value: %f"), TValue);
|
||||||
|
FRotator DeltaRotation = FRotator::ZeroRotator;
|
||||||
|
// Yaw = TValue * DeltaTime * TurnRate;
|
||||||
|
DeltaRotation.Yaw = TValue * TurnRate * UGameplayStatics::GetWorldDeltaSeconds(this);
|
||||||
|
AddActorLocalRotation(DeltaRotation, true);
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,13 @@ public:
|
|||||||
// Called to bind functionality to input
|
// Called to bind functionality to input
|
||||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||||
|
|
||||||
|
// Called every frame
|
||||||
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Called when the game starts or when spawned
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UPROPERTY(VisibleAnywhere, Category = "Components")
|
UPROPERTY(VisibleAnywhere, Category = "Components")
|
||||||
class USpringArmComponent* SpringArm;
|
class USpringArmComponent* SpringArm;
|
||||||
@@ -30,7 +37,11 @@ private:
|
|||||||
UPROPERTY(EditAnywhere, Category = "Movement")
|
UPROPERTY(EditAnywhere, Category = "Movement")
|
||||||
float Speed = 200.f;
|
float Speed = 200.f;
|
||||||
|
|
||||||
void Move(float Value);
|
UPROPERTY(EditAnywhere, Category = "Movement")
|
||||||
|
float TurnRate = 135.f;
|
||||||
|
|
||||||
|
void Move(float Value);
|
||||||
void Turn(float TValue);
|
void Turn(float TValue);
|
||||||
|
|
||||||
|
APlayerController* PlayerControllerRef;
|
||||||
};
|
};
|
||||||
|
|||||||
32
Source/ToonTanks/Tower.cpp
Normal file
32
Source/ToonTanks/Tower.cpp
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "Tower.h"
|
||||||
|
#include "Tank.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
|
void ATower::Tick(float DeltaTime)
|
||||||
|
{
|
||||||
|
Super::Tick(DeltaTime);
|
||||||
|
|
||||||
|
// Find the distance to the tank
|
||||||
|
if (Tank)
|
||||||
|
{
|
||||||
|
float Distance = FVector::Dist(GetActorLocation(), Tank->GetActorLocation());
|
||||||
|
|
||||||
|
// check to see if the tank is in range
|
||||||
|
if (Distance <= FireRange)
|
||||||
|
{
|
||||||
|
// if in range, rotate turret toward the tank
|
||||||
|
RotateTurret(Tank->GetActorLocation());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ATower::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
Tank = Cast<ATank>(UGameplayStatics::GetPlayerPawn(this, 0));
|
||||||
|
}
|
||||||
32
Source/ToonTanks/Tower.h
Normal file
32
Source/ToonTanks/Tower.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "BasePawn.h"
|
||||||
|
#include "Tower.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class TOONTANKS_API ATower : public ABasePawn
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Called when the game starts or when spawned
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
class ATank* Tank;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, Category="Combat")
|
||||||
|
float FireRange = 700.f;
|
||||||
|
|
||||||
|
};
|
||||||
@@ -1,26 +1,23 @@
|
|||||||
{
|
{
|
||||||
"FileVersion": 3,
|
"FileVersion": 3,
|
||||||
"EngineAssociation": "5.6",
|
"EngineAssociation": "5.6",
|
||||||
"Category": "",
|
"Category": "",
|
||||||
"Description": "",
|
"Description": "",
|
||||||
"Modules": [
|
"Modules": [
|
||||||
{
|
{
|
||||||
"Name": "ToonTanks",
|
"Name": "ToonTanks",
|
||||||
"Type": "Runtime",
|
"Type": "Runtime",
|
||||||
"LoadingPhase": "Default"
|
"LoadingPhase": "Default"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"Plugins": [
|
"Plugins": [
|
||||||
{
|
{
|
||||||
"Name": "VisualStudioTools",
|
"Name": "VisualStudioTools",
|
||||||
"Enabled": true,
|
"Enabled": true,
|
||||||
"SupportedTargetPlatforms": [
|
"SupportedTargetPlatforms": [
|
||||||
"Win64"
|
"Win64"
|
||||||
]
|
],
|
||||||
}
|
"MarketplaceURL": "com.epicgames.launcher://ue/marketplace/product/362651520df94e4fa65492dbcba44ae2"
|
||||||
],
|
}
|
||||||
"TargetPlatforms": [],
|
]
|
||||||
"AdditionalRootDirectories": [],
|
|
||||||
"AdditionalPluginDirectories": [],
|
|
||||||
"EpicSampleNameHash": ""
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user