diff --git a/Source/OpenConflict/PlayerCharacter/DDICharacter.cpp b/Source/OpenConflict/PlayerCharacter/DDICharacter.cpp index 7aa05ca..dfc4a9b 100644 --- a/Source/OpenConflict/PlayerCharacter/DDICharacter.cpp +++ b/Source/OpenConflict/PlayerCharacter/DDICharacter.cpp @@ -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(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(OtherActor); + + if (HealthComponent && Projectile) + HealthComponent->TakeDamage(10); +} diff --git a/Source/OpenConflict/PlayerCharacter/DDICharacter.h b/Source/OpenConflict/PlayerCharacter/DDICharacter.h index 6119fe4..27a309a 100644 --- a/Source/OpenConflict/PlayerCharacter/DDICharacter.h +++ b/Source/OpenConflict/PlayerCharacter/DDICharacter.h @@ -4,6 +4,7 @@ #include "CoreMinimal.h" #include "Camera/CameraComponent.h" +#include "Components/DDIHealth.h" #include "GameFramework/Character.h" #include "DDICharacter.generated.h" @@ -12,20 +13,50 @@ UCLASS() class OPENCONFLICT_API ADDICharacter : public ACharacter { GENERATED_BODY() + /*UPROPERTY and UFUNCTION declarations*/ +private: + /*Properties*/ -public: - // Sets default values for this character's properties - ADDICharacter(); + /*Functions*/ protected: + /*Properties*/ + + /*Functions*/ + +public: + /*Properties*/ + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera") + UCameraComponent* CameraComponent; + UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Health") + UDDIHealth* HealthComponent; + + /*Functions*/ + UFUNCTION() + void OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit); + + + /*C++ only declarations*/ +private: + /*Properties*/ + + /*Functions*/ + +protected: + /*Properties*/ + + /*Functions*/ // Called when the game starts or when spawned virtual void BeginPlay() override; -public: +public: + /*Properties*/ + + /*Functions*/ + // Sets default values for this character's properties + ADDICharacter(); // Called every frame virtual void Tick(float DeltaTime) override; - - UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Camera") - UCameraComponent* CameraComponent; - + + };