void ABaseCharacter::OnDeath(float KillingDamage, FDamageEvent const& DamageEvent, APawn* PawnInstigator, AActor* DamageCauser) { bReplicateMovement = false; bTearOff = true; PlayHit(true, KillingDamage, DamageEvent, PawnInstigator, DamageCauser); DetachFromControllerPendingDestroy(); /* Disable all collision on capsule */ UCapsuleComponent* CapsuleComp = GetCapsuleComponent(); CapsuleComp->SetCollisionEnabled(ECollisionEnabled::NoCollision); CapsuleComp->SetCollisionResponseToAllChannels(ECR_Ignore); if(bRagdolledAfterDeath) { SetRagdollPhysics(); ApplyPhysicsToTheRagdolledBody(DamageEvent); } else { SetLifeSpan(TimeAfterDeathBeforeDestroy); } }
void AVehiclePawn::OnDeath() { AVehiclePlayerController* MyPC = Cast<AVehiclePlayerController>(GetController()); bReplicateMovement = false; bIsDying = true; DetachFromControllerPendingDestroy(); // hide and disable TurnOff(); SetActorHiddenInGame(true); if (EngineAC) { EngineAC->Stop(); } if (SkidAC) { SkidAC->Stop(); } PlayDestructionFX(); // Give use a finite lifespan SetLifeSpan( 0.2f ); }
void APawn::EndPlay(const EEndPlayReason::Type EndPlayReason) { // Only do this once, to not be redundant with Destroyed(). if (EndPlayReason != EEndPlayReason::Destroyed) { DetachFromControllerPendingDestroy(); GetWorld()->RemovePawn( this ); } Super::EndPlay(EndPlayReason); }
void APawn::Reset() { if ( (Controller == NULL) || (Controller->PlayerState != NULL) ) { DetachFromControllerPendingDestroy(); Destroy(); } else { Super::Reset(); } }
void AShooterCharacter::OnDeath(float KillingDamage, FDamageEvent const& DamageEvent, APawn* PawnInstigator, AActor* DamageCauser) { if (bIsDying) { return; } bReplicateMovement = false; bTearOff = true; bIsDying = true; PlayHit(KillingDamage, DamageEvent, PawnInstigator, DamageCauser, true); DetachFromControllerPendingDestroy(); /* Disable all collision on capsule */ UCapsuleComponent* CapsuleComp = GetCapsuleComponent(); CapsuleComp->SetCollisionEnabled(ECollisionEnabled::NoCollision); CapsuleComp->SetCollisionResponseToAllChannels(ECR_Ignore); USkeletalMeshComponent* Mesh3P = GetMesh(); if (Mesh3P) { Mesh3P->SetCollisionProfileName(TEXT("Ragdoll")); } SetActorEnableCollision(true); SetRagdollPhysics(); /* Apply physics impulse on the bone of the enemy skeleton mesh we hit (ray-trace damage only) */ if (DamageEvent.IsOfType(FPointDamageEvent::ClassID)) { FPointDamageEvent PointDmg = *((FPointDamageEvent*)(&DamageEvent)); { // TODO: Use DamageTypeClass->DamageImpulse Mesh3P->AddImpulseAtLocation(PointDmg.ShotDirection * 12000, PointDmg.HitInfo.ImpactPoint, PointDmg.HitInfo.BoneName); } } if (DamageEvent.IsOfType(FRadialDamageEvent::ClassID)) { FRadialDamageEvent RadialDmg = *((FRadialDamageEvent const*)(&DamageEvent)); { Mesh3P->AddRadialImpulse(RadialDmg.Origin, RadialDmg.Params.GetMaxRadius(), 100000 /*RadialDmg.DamageTypeClass->DamageImpulse*/, ERadialImpulseFalloff::RIF_Linear); } } }
void AFPSGCharacter::die(AFPSGPlayerController* killer) { if (GEngine != NULL) { //GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Yellow, TEXT("AFPSGCharacter::die")); } //Destroy the player inventory destroyInventory(); AFPSGPlayerController* myPlayerController = Cast<AFPSGPlayerController>(GetController()); if (myPlayerController != NULL) { //Set to true, and when replicated to clients, will call the callback function onRep_DieOwnerOnly in player controller myPlayerController->setDieCallback(true); //We are the server, but just to be sure if (Role == ROLE_Authority) { //Server have to manually call the onRep_DieOwnerOnly callback myPlayerController->onRep_DieOwnerOnly(); AFPSGGameMode* gameMode = GetWorld() ? GetWorld()->GetAuthGameMode<AFPSGGameMode>() : NULL; if (gameMode != NULL) { gameMode->notifyKill(killer, myPlayerController); } } } //Set to true, and when replicated to clients, will call the callback function onRep_DieAll dieCallback = true; //We are the server, but just to be sure if (Role == ROLE_Authority) { //Server have to manually call the onRep_DieAll callback onRep_DieAll(); } //Calls our controller PawnPendingDestroy function DetachFromControllerPendingDestroy(); }
void APawn::OutsideWorldBounds() { if ( !bProcessingOutsideWorldBounds ) { bProcessingOutsideWorldBounds = true; // AI pawns on the server just destroy if (Role == ROLE_Authority && Cast<APlayerController>(Controller) == NULL) { Destroy(); } else { DetachFromControllerPendingDestroy(); TurnOff(); SetActorHiddenInGame(true); SetLifeSpan( FMath::Clamp(InitialLifeSpan, 0.1f, 1.0f) ); } bProcessingOutsideWorldBounds = false; } }
void ALonelyMenCharacter::PlayDie(float KillingDamge, FDamageEvent const& DamageEvent, AController* killer, AActor* DamageCauser) { nCurHealth = FMath::Min(0, nCurHealth); if (bIsDying) return; //play death sound //remove DestroyAllInventory(); DetachFromControllerPendingDestroy(); //disable collison klon capsule GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); GetCapsuleComponent()->SetCollisionResponseToAllChannels(ECR_Ignore); if (GetMesh()) { static FName CollisonProfileName(TEXT("Radoll")); GetMesh()->SetCollisionProfileName(CollisonProfileName); } SetActorEnableCollision(true); //play death anim float DeathAnimDuration = PlayAnimMontage(DeathAnim); //Ragdoll if (DeathAnimDuration > 0) { FTimerHandle TimerHandle; GetWorldTimerManager().SetTimer(TimerHandle, this, &ANonPlayerCharacter::SetRagDollPhysics, FMath::Min(0.1f, DeathAnimDuration), false); } else { SetRagDollPhysics(); } }
void ANimModCharacter::OnDeath(float KillingDamage, struct FDamageEvent const& DamageEvent, class APawn* PawnInstigator, class AActor* DamageCauser) { if (bIsDying) { return; } bReplicateMovement = false; bTearOff = true; bIsDying = true; if (Role == ROLE_Authority) { ReplicateHit(KillingDamage, DamageEvent, PawnInstigator, DamageCauser, true); // play the force feedback effect on the client player controller APlayerController* PC = Cast<APlayerController>(Controller); if (PC && DamageEvent.DamageTypeClass) { UNimModDamageType *DamageType = Cast<UNimModDamageType>(DamageEvent.DamageTypeClass->GetDefaultObject()); if (DamageType && DamageType->KilledForceFeedback) { PC->ClientPlayForceFeedback(DamageType->KilledForceFeedback, false, "Damage"); } } } // cannot use IsLocallyControlled here, because even local client's controller may be NULL here if (GetNetMode() != NM_DedicatedServer && DeathSound && Mesh1P && Mesh1P->IsVisible()) { UGameplayStatics::PlaySoundAtLocation(this, DeathSound, GetActorLocation()); } ANimModPlayerController *controller = GetNimModPlayerController(); if (controller) { ANimModPlayerCameraManager *cameraManager = controller->GetNimModPlayerCameraManager(); if (cameraManager) cameraManager->ResetFOV(); } // remove all weapons DestroyInventory(); // switch back to 3rd person view UpdatePawnMeshes(); DetachFromControllerPendingDestroy(); StopAllAnimMontages(); if (LowHealthWarningPlayer && LowHealthWarningPlayer->IsPlaying()) { LowHealthWarningPlayer->Stop(); } if (RunLoopAC) { RunLoopAC->Stop(); } // disable collisions on capsule GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); GetCapsuleComponent()->SetCollisionResponseToAllChannels(ECR_Ignore); if (GetMesh()) { static FName CollisionProfileName(TEXT("Ragdoll")); GetMesh()->SetCollisionProfileName(CollisionProfileName); } SetActorEnableCollision(true); // Death anim float DeathAnimDuration = PlayAnimMontage(DeathAnim); // Ragdoll if (DeathAnimDuration > 0.f) { // Use a local timer handle as we don't need to store it for later but we don't need to look for something to clear FTimerHandle TimerHandle; GetWorldTimerManager().SetTimer(TimerHandle, this, &ANimModCharacter::SetRagdollPhysics, FMath::Min(0.1f, DeathAnimDuration), false); } else { SetRagdollPhysics(); } }
void APawn::Destroyed() { DetachFromControllerPendingDestroy(); GetWorld()->RemovePawn( this ); Super::Destroyed(); }