Damage Events

So I am going through simple shooter and im at the part where we do damage. I wanted to use a projectile instead of the line trace because I wanted the projectiles to be dodgeable. The problem is that now in order to deal damage in the lecture we use line tracing and im here stuck with my projectile. What are my options? Can I add a very short line trace to my projectile and add damage like that (will that work?) or is there a way to apply damage with projectiles that im unaware of?

If you have already projectile mechanics figured out then applying damage is simple, just call UGameplayStatics::ApplyPointDamage when your projectile hits valid target.

So just call that in here?

void AFPSProjectile::OnHit(UPrimitiveComponent* HitComponent, AActor* OtherActor, UPrimitiveComponent* OtherComponent, FVector NormalImpulse, const FHitResult& Hit)

    if (OtherActor != this && OtherComponent->IsSimulatingPhysics())
        OtherComponent->AddImpulseAtLocation(ProjectileMovementComponent->Velocity * 100.0f, Hit.ImpactPoint);


Looks like a good place.

In Ue4 docs it says the following for the syntax of ApplyPointDamage:

static float ApplyPointDamage
    AActor * DamagedActor,
    float BaseDamage,
    const FVector & HitFromDirection,
    const FHitResult & HitInfo,
    AController * EventInstigator,
    AActor * DamageCauser,
    TSubclassOf < class UDamageType > DamageTypeClass

What do I put for these, which of these do I need?

Would probably be easier to use TakeDamage which is used in the course and use it on the actor which your projectile hits which is one of the parameters of that OnHit function.

So the syntax that ue4 docs show is the following:

virtual float TakeDamage
    float DamageAmount,
    struct FDamageEvent const & DamageEvent,
    class AController * EventInstigator,
    AActor * DamageCauser

So I get the first one, thats simple. However the description for the second one is: DamageEvent Data package that fully describes the damage received. I dont get what to put for that. For the third one it says: EventInstigator The Controller responsible for the damage. What am I supposed to put for that? I get how to do the last one.

Similar to what was done in Simple Shooter


Instigator would be the controller that fired the projectile and DamageCauser would be the projectile.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.