Add basic class files

This commit is contained in:
2025-02-15 21:30:02 +05:30
parent 07ed6f8876
commit bb4d1bef59
6 changed files with 352 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
#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();
}