43 lines
1.5 KiB
C++
43 lines
1.5 KiB
C++
#include "SpaceshipProjectile.h"
|
|
#include "GameFramework/ProjectileMovementComponent.h"
|
|
#include "Components/StaticMeshComponent.h"
|
|
|
|
ASpaceshipProjectile::ASpaceshipProjectile()
|
|
{
|
|
PrimaryActorTick.bCanEverTick = true;
|
|
|
|
// Create and setup the projectile mesh
|
|
ProjectileMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ProjectileMesh"));
|
|
RootComponent = ProjectileMesh;
|
|
ProjectileMesh->SetCollisionProfileName(TEXT("Projectile"));
|
|
ProjectileMesh->OnComponentHit.AddDynamic(this, &ASpaceshipProjectile::OnHit);
|
|
|
|
// Create and setup projectile movement
|
|
ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovement"));
|
|
ProjectileMovement->UpdatedComponent = ProjectileMesh;
|
|
ProjectileMovement->InitialSpeed = ProjectileSpeed;
|
|
ProjectileMovement->MaxSpeed = ProjectileSpeed;
|
|
ProjectileMovement->bRotationFollowsVelocity = true;
|
|
ProjectileMovement->ProjectileGravityScale = 0.0f;
|
|
|
|
// Set lifetime
|
|
InitialLifeSpan = 3.0f;
|
|
}
|
|
|
|
void ASpaceshipProjectile::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
}
|
|
|
|
void ASpaceshipProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
|
|
FVector NormalImpulse, const FHitResult& Hit)
|
|
{
|
|
if (OtherActor && OtherActor != this)
|
|
{
|
|
// Apply damage to the hit actor (if it implements damage interface)
|
|
FDamageEvent DamageEvent;
|
|
OtherActor->TakeDamage(DamageAmount, DamageEvent, nullptr, this);
|
|
}
|
|
|
|
Destroy();
|
|
} |