Hey! I am trying to create a simple damage script using collision overlap. What I am trying to do exactly is that I call a function on "OtherActor"s Script called “ApplyDamage” and send the damage that the projectile should do to the player. Anyone know how I would do this?
Here is what I am using at the moment.
void ACollectable::OnOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL))
{
if (OtherActor->IsA(AFPSCharacter::StaticClass())) //check if a player was hit
{
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Black, "Collision with health object!");
OtherComp->ApplyDamage(Damage); //obviously this does not work, but maybe something along those lines?
MeshComp->DestroyComponent();
}
}
}
I ended up doing something different, but how does “TakeDamage” actually work? Do you have to define your health variable in it or something? Always confused me a lot…anyway, thanks for your reply! +1 This is probably a pretty good solution to the problem as well