Collision and Damage between Projectile and Character

Hello all !

I’m new with Unreal Engine 4.6 and I want to create a FPS game for training.

I have a custom character class “HumanCharacter” and a custom projectile class “Projectile”.

My character has two variables “float Health” and “float AttackValue” and I want to do this “Health -= EnemyAttackValue;” anywhere (of course with functions, it’s just for example).

I tried with “void OnHit” function but doesn’t work (when my projectile “hit” my character, there is a collision with it but the function OnHit is not called).

So… Does anyone have a simple solution to a damage system between two characters who shot above? A solution with explanations would be welcome, and all this in C++ obviously. :slight_smile:

Thanks,

VinsV

Add a delegate to handle OnStop or OnBounce from the ProjectilleMovementComponent in your Projectile Actor. Get the Actor from the hit result if it exists. Do UGameplayStatics::ApplyDamage to the actor passing in AttackValue for BaseDamage. Inside TakeDamage on your character class you can subtract the incoming damage from Health.

Ok I understand this idea, but can you explain me how to add a delegate to handle please ?

Where I call ApplyDamage ? In the projectile class ?

Thank you for your answer anyway !


ProjectileMovement->OnProjectileStop.AddDynamic(this, &AMyProjectileActor::OnStop);
void AMyProjectileActor::OnStop(const FHitResult& HitResult);

	AActor* HitActor = HitResult.GetActor();
if(HitActor != nullptr)
{
AController EventInstigator = my instigating controller
UGameplayStatics::ApplyDamage(DamagedActor, AttackValue, EventInstigator , this, my damage type);

}


Look at the shooter game for a more complete example.

Thanks !

Shooter game is the base Unreal Project when I want to create a new project or a Shooter game in the market ?

shoot game in the marketplace