Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Missile functionality to 4.21.2 #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 33 additions & 32 deletions Source/MissileDemo/Missile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include "Missile.h"
#include "MissileDemo.h"
#include "MyCharacter.h"
#include "Components/BoxComponent.h"
#include "Kismet/GameplayStatics.h"
#include "EngineUtils.h"

// Sets default values
AMissile::AMissile(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
Expand All @@ -16,8 +19,6 @@ AMissile::AMissile(const FObjectInitializer& ObjectInitializer) : Super(ObjectIn

// Construct Static Mesh Component
MissileMesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("MissileMesh"));
const ConstructorHelpers::FObjectFinder<UStaticMesh> MeshObj(TEXT("/Game/Missile/Missile_01_Model"));
MissileMesh->SetStaticMesh(MeshObj.Object);
MissileMesh->SetupAttachment(RootComponent);

// Construct Projectile Movement Component
Expand All @@ -34,7 +35,7 @@ AMissile::AMissile(const FObjectInitializer& ObjectInitializer) : Super(ObjectIn
ProjectileMovement->Velocity = FVector(0, 0, 0);

// Bind our OnOverlapBegin Event
CollisionComp->OnComponentBeginOverlap.AddDynamic(this, &AMissile::OnOverlapBegin);
//CollisionComp->OnComponentBeginOverlap.AddDynamic(this, &AMissile::OnOverlapBegin);

// Set Default Values for Variables
hasTargetPosition = false;
Expand All @@ -44,7 +45,7 @@ AMissile::AMissile(const FObjectInitializer& ObjectInitializer) : Super(ObjectIn
hasFinishedDelay = false;
lifetimeCountdown = 15.f;
canBeDestroyed = false;
PlayerInWorld = NULL;
PlayerCharacter = NULL;
}

#pragma region Setup Target Logic
Expand Down Expand Up @@ -80,9 +81,9 @@ void AMissile::FindPlayer()
{
if (FoundPlayer->ActorHasTag(PlayerTagName))
{
if (PlayerInWorld != FoundPlayer)
if (PlayerCharacter != FoundPlayer)
{
PlayerInWorld = FoundPlayer;
PlayerCharacter = FoundPlayer;
}
}
}
Expand All @@ -95,11 +96,11 @@ void AMissile::UpdateTarget()
{
if (!hasTargetPosition)
{
if (PlayerInWorld != NULL)
if (target == NULL)
{
if (PlayerInWorld->IsValidLowLevel())
if (PlayerCharacter->IsValidLowLevel())
{
target = PlayerInWorld;
target = PlayerCharacter;
hasTargetPosition = true;
hasNoTarget = false;

Expand Down Expand Up @@ -201,29 +202,29 @@ void AMissile::Tick(float DeltaTime)

#pragma region Overlap Events
// If our missile overlaps the player or the ground, it will be destroyed
void AMissile::OnOverlapBegin(UPrimitiveComponent* overlappedComp, AActor* otherActor, UPrimitiveComponent* otherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &hitResult)
{
class AMyCharacter* PlayerCharacter = Cast<AMyCharacter>(otherActor);
class AStaticMeshActor* GroundActor = Cast<AStaticMeshActor>(otherActor);

if (PlayerCharacter != nullptr)
{
PlayExplosion(ExplosionSystem);
PlayExplosionSound(ExplosionSound);

if (this->IsValidLowLevel())
Destroy();
}

if (GroundActor != nullptr)
{
PlayExplosion(ExplosionSystem);
PlayExplosionSound(ExplosionSound);

if (this->IsValidLowLevel())
Destroy();
}
}
//void AMissile::OnOverlapBegin(UPrimitiveComponent* overlappedComp, AActor* otherActor, UPrimitiveComponent* otherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &hitResult)
//{
// class AMyCharacter* PlayerCharacter = Cast<AMyCharacter>(otherActor);
// class AStaticMeshActor* GroundActor = Cast<AStaticMeshActor>(otherActor);
//
// if (PlayerCharacter != nullptr)
// {
// PlayExplosion(ExplosionSystem);
// PlayExplosionSound(ExplosionSound);
//
// if (this->IsValidLowLevel())
// Destroy();
// }
//
// if (GroundActor != nullptr)
// {
// PlayExplosion(ExplosionSystem);
// PlayExplosionSound(ExplosionSound);
//
// if (this->IsValidLowLevel())
// Destroy();
// }
//}
#pragma endregion

#pragma region End of Play Logic
Expand Down
8 changes: 5 additions & 3 deletions Source/MissileDemo/Missile.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#pragma once

#include "CoreMinimal.h"
#include "Components/StaticMeshComponent.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "GameFramework/Actor.h"
#include "Missile.generated.h"

Expand All @@ -28,8 +30,8 @@ class MISSILEDEMO_API AMissile : public AActor
void Explode();

// Event to Detect When an Actor Overlaps the Missile Class
UFUNCTION()
void OnOverlapBegin(UPrimitiveComponent* overlappedComp, AActor* otherActor, UPrimitiveComponent* otherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &hitResult);
//UFUNCTION()
//void OnOverlapBegin(UPrimitiveComponent* overlappedComp, AActor* otherActor, UPrimitiveComponent* otherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult &hitResult);

public:

Expand All @@ -43,7 +45,7 @@ class MISSILEDEMO_API AMissile : public AActor

// Reference To Our Player in World
UPROPERTY()
class AMyCharacter* PlayerInWorld;
class AActor* PlayerCharacter;

public:

Expand Down