void ABomb::PerformDelayedExplosion(float ExplosionDelay) { FTimerHandle TimerHandle; FTimerDelegate TimerDel; TimerDel.BindUFunction(this, FName("Explode")); GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDel, ExplosionDelay, false); }
void AGungrenagesGameMode::gameOver() { FTimerHandle h; FTimerDelegate del; del.BindLambda([this]() { UGameplayStatics::OpenLevel(GetWorld(), FName("/Game/Gungrenages/UI/GameOverLevel")); }); GetWorld()->GetTimerManager().SetTimer(h, del, 3.0f, false); }
void AAICharacter::AnswerToCharacter(FName PlayerLine, TArray<FSubtitle>& SubtitlesToDisplay, float delay) { if (!AILines) return; //Retrieve the corresponding line FString ContextString; FDialog* Dialog = AILines->FindRow<FDialog>(PlayerLine, ContextString); ADialogSystemCharacter* MainChar = Cast<ADialogSystemCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)); if (Dialog && MainChar) { FTimerHandle TimerHandle; FTimerDelegate TimerDel; TimerDel.BindUFunction(this, FName("Talk"), Dialog->SFX, Dialog->Subtitles); //Talk to the player after the delay time has passed GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDel, delay, false); } }
void ABomb::Explode() { SimulateExplosionFX(); //We won't use any specific damage types in our case TSubclassOf<UDamageType> DmgType; //Do not ignore any actors TArray<AActor*> IgnoreActors; //This will eventually call the TakeDamage function that we have overriden in the Character class UGameplayStatics::ApplyRadialDamage(GetWorld(), ExplosionDamage, GetActorLocation(), ExplosionRadius, DmgType, IgnoreActors, this, GetInstigatorController()); FTimerHandle TimerHandle; FTimerDelegate TimerDel; TimerDel.BindLambda([&]() { Destroy(); }); //Destroy the actor after 0.3 seconds. GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDel, 0.3f, false); }
//------------------------------------------------------------------------------------- //Creates a closed area using the character's position as its center and enables //the bouncing effect on all the projectiles for the lifespan of the area. //------------------------------------------------------------------------------------- void ARnCCharacter::CreateProjectileBounceArea() { if(BounceAreaBP) { //The spawn params that are used in all spawns FActorSpawnParameters SpawnParams; DECLARE_DELEGATE_TwoParams(BounceAreaSpawner, FVector, FRotator); BounceAreaSpawner Delegate; //Spawns a wall based on the relative location and rotation given Delegate.BindLambda([&](FVector WallRelativeLocation, FRotator WallRelativeRotation) { //Take into consideration the location of the player in order to spawn the walls around him WallRelativeLocation += GetActorLocation(); WallRelativeRotation += GetActorRotation(); //Create the desired transform FTransform WallTransform; WallTransform.SetLocation(WallRelativeLocation); WallTransform.SetRotation(WallRelativeRotation.Quaternion()); //Spawn the wall and apply the desired scale AProjectileBounceArea* BounceArea = GetWorld()->SpawnActor<AProjectileBounceArea>(BounceAreaBP, WallTransform, SpawnParams); if (BounceArea) { BounceArea->SetActorScale3D(UnifiedScaleMultiplier); BounceArea->SetLifeSpan(LifeTimeOfBounceArea); } }); if(Delegate.IsBound()) { //Enable the battle cry animation if (MainCharAnimInstance) { bIsInBattleCry = true; MainCharAnimInstance->EnableBattlecry(); } //Enabling projectile bouncing effect bShouldProjectilesBounce = true; //Disable the projectiles bouncing after a certain amount of time FTimerHandle TimerHandle; FTimerDelegate TimerDelegate; TimerDelegate.BindLambda([&]() { bShouldProjectilesBounce = false; }); GetWorld()->GetTimerManager().SetTimer(TimerHandle, TimerDelegate, LifeTimeOfBounceArea, false); //We're going to use the following vectors in order to spawn the walls in the desired rotation and location FVector ForwardActorVector = GetActorForwardVector(); FVector RightActorVector = GetActorRightVector(); //Spawning the wall that the player will face Delegate.Execute(ForwardActorVector * ForwardVectorMultiplier, FRotator::ZeroRotator); //Spawning the wall right behind the player Delegate.Execute((ForwardActorVector * -1) * ForwardVectorMultiplier, FRotator::ZeroRotator); //Spawning the wall on the right side of the player Delegate.Execute(RightActorVector * RightVectorMultiplier, FRotator(0, 90.f, 0)); //Spawning the wall on the left side of the player Delegate.Execute((RightActorVector * -1) * RightVectorMultiplier, FRotator(0, 90.f, 0)); //Spawning the "ceiling" wall Delegate.Execute(GetActorUpVector() * UpVectorMultiplier, FRotator(90.f,0,0)); } } }