Hello!
I’m trying to make my character able to pick up projectiles on LMB and I need some help.
“Pick up” action works only when LMB is pressed before character collides with projectile. But if character already collides with projectile, LMB will do nothing and projectile is not destroyed.
void AFPSBall::OnOverlapBegin(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp,
int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
AFPSCharacter* player = Cast<AFPSCharacter> (OtherActor);
checkingPickUp = player->requestPickUp;
if (checkingPickUp == true)
{
if ((OtherActor != nullptr) && (OtherActor != this) && (OtherComp != nullptr))
{
Destroy();
checkingThrown = false;
player->ballIsThrown = checkingThrown;
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Green, TEXT("Ball is picked up"));
}
}
}
FPSCharacter.cpp
void AFPSCharacter::StartPickUp()
{
requestPickUp = true; // LMB pressed
}
void AFPSCharacter::EndPickUp()
{
requestPickUp = false; // LMB released
}
Is it possible to call OnOverlapBegin every frame when checkingPickUp is true?
void AFPSBall::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (checkingPickUp == true)
{
OnOverlapBegin; // ?????
}
}