You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.9 KiB

9 months ago
// Copyright Zelle Games
#include "BasicProjectile.h"
#include "Components/SphereComponent.h"
#include "Engine/DamageEvents.h"
#include "GameFramework/ProjectileMovementComponent.h"
// Sets default values
ABasicProjectile::ABasicProjectile()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Collision"));
SphereComponent->InitSphereRadius(50.0f);
RootComponent = SphereComponent;
SphereComponent->OnComponentBeginOverlap.AddDynamic(this, &ABasicProjectile::OnSphereOverlap);
SphereComponent->SetCollisionProfileName("NoCollision");
MeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("Mesh"));
MeshComponent->SetCollisionProfileName("NoCollision");
MeshComponent->SetupAttachment(RootComponent);
ProjectileMovementComponent = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("Projectile Movement"));
ProjectileMovementComponent->SetUpdatedComponent(RootComponent);
ProjectileMovementComponent->ProjectileGravityScale = 0;
}
// Called when the game starts or when spawned
void ABasicProjectile::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ABasicProjectile::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void ABasicProjectile::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
FVector UnitDirection = OtherActor->GetActorLocation() - GetActorLocation();
UnitDirection.Normalize();
FPointDamageEvent DamageEvent;
DamageEvent.HitInfo.ImpactPoint = SweepResult.ImpactPoint;
DamageEvent.ShotDirection = UnitDirection;
DamageEvent.Damage = Damage;
OtherActor->TakeDamage(Damage, DamageEvent, nullptr, this);
Destroy();
}