Hi, I’m using c++ for Unreal Engine 4.10.4
I’m creating a base melee attack system for character (it’s the default third person character class).
In input action for simple attack I’ve done it:
And in c++ class (FinalWardCharacter.cpp) I’ve added this:
InputComponent->BindAction(“SimpleAttack”, IE_Pressed, this, &AFinalWardCharacter::AttackSimple);
InputComponent->BindAction(“SimpleAttack”, IE_Released, this, &AFinalWardCharacter::StopAttackSimple);
Sword->OnComponentHit.AddDynamic(this, &AFinalWardCharacter::OnHit);
void AFinalWardCharacter::AttackSimple()
{
isAttacking = true;
UE_LOG(LogTemp, Warning, TEXT(“start attack”));
}
void AFinalWardCharacter::StopAttackSimple()
{
isAttacking = false;
UE_LOG(LogTemp, Warning, TEXT(“finish attack”));
}
void AFinalWardCharacter::OnHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit)
{
if (OtherActor != this && isAttacking)
{
OtherActor->TakeDamage(AttackDamage, FDamageEvent(), NULL, this);
UE_LOG(LogTemp, Warning, TEXT(“collision!”));
}
}
But there is a problem:
if I press left mouse and I don’t release it, character continues to inflict damage to other entity…I need he does it only one time.
How can I resolve it?