Working on netowrked projectiles
This commit is contained in:
@@ -3,14 +3,22 @@
|
||||
|
||||
#include "ProjectileBase.h"
|
||||
|
||||
#include "OpenConflict/PlayerCharacter/DDICharacter.h"
|
||||
|
||||
// Sets default values
|
||||
AProjectileBase::AProjectileBase()
|
||||
{
|
||||
// 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;
|
||||
bReplicates = true;
|
||||
bNetLoadOnClient = true;
|
||||
|
||||
InitialLifeSpan = 3.f;
|
||||
|
||||
|
||||
collision = CreateDefaultSubobject<USphereComponent>("Collision");
|
||||
RootComponent = collision;
|
||||
collision->BodyInstance.SetCollisionProfileName(TEXT("BlockAllDynamic"));
|
||||
|
||||
projectileMesh = CreateDefaultSubobject<UStaticMeshComponent>("ProjectileMesh");
|
||||
projectileMesh->SetupAttachment(collision);
|
||||
@@ -22,6 +30,9 @@ AProjectileBase::AProjectileBase()
|
||||
void AProjectileBase::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
if (collision)
|
||||
collision->OnComponentHit.AddDynamic(this, &AProjectileBase::OnHit);
|
||||
|
||||
}
|
||||
|
||||
@@ -32,3 +43,12 @@ void AProjectileBase::Tick(float DeltaTime)
|
||||
|
||||
}
|
||||
|
||||
|
||||
void AProjectileBase::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
|
||||
{
|
||||
if (ADDICharacter* character = Cast<ADDICharacter>(OtherActor))
|
||||
{
|
||||
Destroy();
|
||||
character->TakeDamage(10);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user