diff --git a/Content/Blueprints/Pawns/BP_PawnTurret.uasset b/Content/Blueprints/Pawns/BP_PawnTurret.uasset index 57ce18b..f312497 100644 --- a/Content/Blueprints/Pawns/BP_PawnTurret.uasset +++ b/Content/Blueprints/Pawns/BP_PawnTurret.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6e6ff48b245c6dc3502bea23164cb968190e923db2aa2dd316ffc16d79022e9d -size 33865 +oid sha256:80f2b88b8aacf22db6ac564099014b40fc57c37005353f80cf3b775a41b32a40 +size 34184 diff --git a/Source/ToonTanks/Tower.cpp b/Source/ToonTanks/Tower.cpp new file mode 100644 index 0000000..b7f31c1 --- /dev/null +++ b/Source/ToonTanks/Tower.cpp @@ -0,0 +1,27 @@ +// 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); + + if (Tank) + { + float Distance = FVector::Dist(this->GetActorLocation(), Tank->GetActorLocation()); + if (Distance <= FireRange) + { + RotateTurret(Tank->GetActorLocation()); + } + } +} + +void ATower::BeginPlay() +{ + Super::BeginPlay(); + + Tank = Cast(UGameplayStatics::GetPlayerPawn(this, 0)); +} \ No newline at end of file diff --git a/Source/ToonTanks/Tower.h b/Source/ToonTanks/Tower.h new file mode 100644 index 0000000..fcdf1f0 --- /dev/null +++ b/Source/ToonTanks/Tower.h @@ -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: + + virtual void BeginPlay() override; + +private: + + class ATank* Tank; + + UPROPERTY(EditAnywhere, Category = "Rotate") + float FireRange = 400; + +};