Add basic class files
This commit is contained in:
43
Source/MyProject3/SpaceshipProjectile.cpp
Normal file
43
Source/MyProject3/SpaceshipProjectile.cpp
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user