Hi,
I am trying to add a impulse to an object when a projectile hits it.
I tried to edit the first person c++ code to do it.
The .h file.
UFUNCTION()
void OnComponentHit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit);
.cpp file
CollisionComp = PCIP.CreateDefaultSubobject<USphereComponent>(this, TEXT("SphereComp"));
CollisionComp->InitSphereRadius(5.0f);
CollisionComp->OnComponentHit.AddDynamic(this, &AMyProjectProjectile::OnComponentHit); // set up a notification for when this component overlaps something
RootComponent = CollisionComp;
void AMyProjectProjectile::OnComponentHit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("HIT"));
}
The OnComponentHit doesn’t seem to trigger for some reason.
Although I don’t have much idea how delegates works. Or why we use OnComponentHit.AddDynamic “adddynamic” here. Can some one explain me the code a little?
** Delegate for notification of blocking collision against a specific component.
* NormalImpulse will be filled in for physics-simulating bodies, but will be zero for swept-component blocking collisions.
*/
DECLARE_DYNAMIC_MULTICAST_DELEGATE_FourParams( FComponentHitSignature, class AActor*, OtherActor, class UPrimitiveComponent*, OtherComp, FVector, NormalImpulse, const FHitResult&, Hit );