setup hits on character
This commit is contained in:
@@ -2,7 +2,10 @@
|
||||
|
||||
|
||||
#include "DDICharacter.h"
|
||||
|
||||
#include "Components/CapsuleComponent.h"
|
||||
#include "GameFramework/SpringArmComponent.h"
|
||||
#include "OpenConflict/Weapons/Projectiles/ProjectileBase.h"
|
||||
|
||||
// Sets default values
|
||||
ADDICharacter::ADDICharacter()
|
||||
@@ -17,6 +20,12 @@ ADDICharacter::ADDICharacter()
|
||||
CameraComponent->SetRelativeLocation(FVector(0.0f, 0.0f, 50.0f));
|
||||
CameraComponent->bUsePawnControlRotation = true;
|
||||
|
||||
HealthComponent = CreateDefaultSubobject<UDDIHealth>(TEXT("HealthComponent"));
|
||||
|
||||
GetCapsuleComponent()->SetCollisionProfileName(TEXT("BlockAllDynamic"));
|
||||
GetCapsuleComponent()->SetGenerateOverlapEvents(true);
|
||||
GetCapsuleComponent()->SetNotifyRigidBodyCollision(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -24,6 +33,11 @@ ADDICharacter::ADDICharacter()
|
||||
void ADDICharacter::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
if (GetCapsuleComponent())
|
||||
{
|
||||
GetCapsuleComponent()->OnComponentHit.AddDynamic(this, &ADDICharacter::OnHit);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,4 +48,13 @@ void ADDICharacter::Tick(float DeltaTime)
|
||||
|
||||
}
|
||||
|
||||
void ADDICharacter::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
|
||||
{
|
||||
if (OtherActor->Owner == this)
|
||||
return;
|
||||
|
||||
AProjectileBase* Projectile = Cast<AProjectileBase>(OtherActor);
|
||||
|
||||
if (HealthComponent && Projectile)
|
||||
HealthComponent->TakeDamage(10);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user