diff --git a/Content/Blueprints/Pawns/BP_PawnTank.uasset b/Content/Blueprints/Pawns/BP_PawnTank.uasset index c3008bd..dd9ae45 100644 --- a/Content/Blueprints/Pawns/BP_PawnTank.uasset +++ b/Content/Blueprints/Pawns/BP_PawnTank.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b99506c7783c067bbc2a5e4b485ab34df92cb74f2f88d1f939b886b79dc64d03 -size 37849 +oid sha256:7746e90f50e6d2dc0c841f00796f10ab58aa882de6049cfc1c6c87d8ebd95ebb +size 37786 diff --git a/Content/Maps/Main.umap b/Content/Maps/Main.umap index 3a36b96..304d5bb 100644 --- a/Content/Maps/Main.umap +++ b/Content/Maps/Main.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:536d966e6ddb3f35a834be5a05ef90bd908b599e2f0913155a32e1cd3f25ab99 -size 95209 +oid sha256:4f9990606a34a1596a3a6c3e5b039c96cba89c60ece1b2db209a09e0861d850e +size 124468 diff --git a/Source/ToonTanks/BasePawn.cpp b/Source/ToonTanks/BasePawn.cpp index acca5c1..e3fea92 100644 --- a/Source/ToonTanks/BasePawn.cpp +++ b/Source/ToonTanks/BasePawn.cpp @@ -4,6 +4,7 @@ #include "BasePawn.h" #include "Components/CapsuleComponent.h" +#include "Kismet/GameplayStatics.h" // Sets default values ABasePawn::ABasePawn() @@ -23,3 +24,16 @@ ABasePawn::ABasePawn() ProjectileSpawnPoint = CreateDefaultSubobject(TEXT("Projectile Spawn Point")); ProjectileSpawnPoint->SetupAttachment(TurretMesh); } + +void ABasePawn::RotateTurret(FVector LookAtTarget) +{ + FVector ToTarget = LookAtTarget - TurretMesh->GetComponentLocation(); + FRotator LookAtRotation = FRotator(0, ToTarget.Rotation().Yaw, 0); + TurretMesh->SetWorldRotation( + FMath::RInterpTo( + TurretMesh->GetComponentRotation(), + LookAtRotation, + UGameplayStatics::GetWorldDeltaSeconds(this), + 5) + ); +} diff --git a/Source/ToonTanks/BasePawn.h b/Source/ToonTanks/BasePawn.h index e77fe33..d7d83e4 100644 --- a/Source/ToonTanks/BasePawn.h +++ b/Source/ToonTanks/BasePawn.h @@ -15,6 +15,10 @@ public: // Sets default values for this pawn's properties ABasePawn(); +protected: + + void RotateTurret(FVector LookAtTarget); + private: UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Component", meta=(AllowPrivateAccess = "true")) class UCapsuleComponent* CapsuleComp; diff --git a/Source/ToonTanks/Tank.cpp b/Source/ToonTanks/Tank.cpp index 9c860cf..ef4b980 100644 --- a/Source/ToonTanks/Tank.cpp +++ b/Source/ToonTanks/Tank.cpp @@ -41,7 +41,7 @@ void ATank::Tick(float DeltaTime) 25, 12, FColor::Green); - + RotateTurret(HitResult.ImpactPoint); } } @@ -51,14 +51,6 @@ void ATank::BeginPlay() Super::BeginPlay(); PlayerControllerRef = Cast(GetController()); - DrawDebugSphere( - GetWorld(), - GetActorLocation() + FVector(0, 0, 200), - 100, - 12, - FColor::Red, - false, - 30); } void ATank::Move(float Value)