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.
|
||||
|
||||
|
||||
#include "Components/CapsuleComponent.h"
|
||||
#include "BasePawn.h"
|
||||
#include "Components/CapsuleComponent.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
// Sets default values
|
||||
ABasePawn::ABasePawn()
|
||||
@@ -24,20 +25,40 @@ ABasePawn::ABasePawn()
|
||||
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void ABasePawn::BeginPlay()
|
||||
void ABasePawn::RotateTurret(FVector LookAtTarget)
|
||||
{
|
||||
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
|
||||
void ABasePawn::Tick(float DeltaTime)
|
||||
/*void ABasePawn::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
/*FVector DeltaLocation(0.f);
|
||||
DeltaLocation.X = 2.f;
|
||||
AddActorLocalOffset(DeltaLocation);*/
|
||||
AddActorLocalOffset(DeltaLocation);
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
@@ -31,10 +31,10 @@ public:
|
||||
UPROPERTY(EditInstanceOnly)
|
||||
int32 EditInstanceOnlyInt = 14;
|
||||
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
void RotateTurret(FVector LookAtTarget);
|
||||
void Fire();
|
||||
|
||||
private:
|
||||
|
||||
@@ -56,9 +56,5 @@ private:
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Super Duper Variables", meta = (AllowPrivateAccess = "true"))
|
||||
int32 VisibleAnywhere = 12;
|
||||
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Components/InputComponent.h"
|
||||
#include "DrawDebugHelpers.h"
|
||||
|
||||
ATank::ATank()
|
||||
{
|
||||
@@ -25,8 +26,53 @@ void ATank::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||
|
||||
PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &ATank::Move);
|
||||
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)
|
||||
@@ -42,5 +88,8 @@ void ATank::Move(float Value)
|
||||
void ATank::Turn(float 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
|
||||
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:
|
||||
UPROPERTY(VisibleAnywhere, Category = "Components")
|
||||
class USpringArmComponent* SpringArm;
|
||||
@@ -30,7 +37,11 @@ private:
|
||||
UPROPERTY(EditAnywhere, Category = "Movement")
|
||||
float Speed = 200.f;
|
||||
|
||||
void Move(float Value);
|
||||
UPROPERTY(EditAnywhere, Category = "Movement")
|
||||
float TurnRate = 135.f;
|
||||
|
||||
void Move(float Value);
|
||||
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,
|
||||
"EngineAssociation": "5.6",
|
||||
"Category": "",
|
||||
"Description": "",
|
||||
"Modules": [
|
||||
{
|
||||
"Name": "ToonTanks",
|
||||
"Type": "Runtime",
|
||||
"LoadingPhase": "Default"
|
||||
}
|
||||
],
|
||||
"Plugins": [
|
||||
{
|
||||
"Name": "VisualStudioTools",
|
||||
"Enabled": true,
|
||||
"SupportedTargetPlatforms": [
|
||||
"Win64"
|
||||
]
|
||||
}
|
||||
],
|
||||
"TargetPlatforms": [],
|
||||
"AdditionalRootDirectories": [],
|
||||
"AdditionalPluginDirectories": [],
|
||||
"EpicSampleNameHash": ""
|
||||
"FileVersion": 3,
|
||||
"EngineAssociation": "5.6",
|
||||
"Category": "",
|
||||
"Description": "",
|
||||
"Modules": [
|
||||
{
|
||||
"Name": "ToonTanks",
|
||||
"Type": "Runtime",
|
||||
"LoadingPhase": "Default"
|
||||
}
|
||||
],
|
||||
"Plugins": [
|
||||
{
|
||||
"Name": "VisualStudioTools",
|
||||
"Enabled": true,
|
||||
"SupportedTargetPlatforms": [
|
||||
"Win64"
|
||||
],
|
||||
"MarketplaceURL": "com.epicgames.launcher://ue/marketplace/product/362651520df94e4fa65492dbcba44ae2"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user