void AATCharacterAI_Magic::Attack(EAttackType EType, int AnimationState) { if (AttackMontageList[AnimationState] != nullptr && EType == EAttackType::EAttack_Attack && !ATAnimInstance->Montage_IsPlaying(AttackMontageList[AnimationState])) { PlayAnimMontage(AttackMontageList[AnimationState]); if (bIsAttacking) { FTimerHandle AttackTimerHandle; GetWorldTimerManager().SetTimer(AttackTimerHandle, this, &AATCharacterAI_Magic::OnAttackEnd, AttackMontageList[AnimationState]->GetPlayLength() + FiringDelay, false); AttackType = EAttackType::EAttack_None; GetCharacterMovement()->MaxWalkSpeed = 0.f; } } }
void ANimModCharacter::OnMontageEnded(UAnimMontage* Montage, bool bInterrupted) { if (CurrentWeapon == nullptr) return; USkeletalMeshComponent* UseMesh = GetPawnMesh(); if (UseMesh && UseMesh->AnimScriptInstance) { if (!UseMesh->AnimScriptInstance->Montage_IsPlaying(nullptr)) { UAnimMontage *idleAnimation = CurrentWeapon->GetIdleAnimation(); if (idleAnimation) PlayAnimMontage(idleAnimation); } } }
float ATopDownShmupCharacter::TakeDamage(float Damage, struct FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser) { float ActualDamage = Super::TakeDamage(Damage, DamageEvent, EventInstigator, DamageCauser); if (ActualDamage > 0.0f) { health -= ActualDamage; if (health <= 0.0f) { //Unpossesses our character/Plays Death Anim/Then Destroys bCanBeDamaged = false; UnPossessed(); CharDeathTime = PlayAnimMontage(CharDeathAnim); GetWorldTimerManager().SetTimer(CharDeathTimerHandle, this, &ATopDownShmupCharacter::CharDieTimer, 1.0f, true); } } return ActualDamage; }
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 AFPSGCharacter::onRep_DieAll() { //GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Magenta, "AFPSGCharacter::onRep_Die"); if (dieCallback) { bReplicateMovement = false; bTearOff = true; //Disable capsule collision if (GetCapsuleComponent() != NULL) { GetCapsuleComponent()->SetCollisionEnabled(ECollisionEnabled::NoCollision); GetCapsuleComponent()->SetCollisionResponseToAllChannels(ECR_Ignore); } //TODO Should stop all animation montages here //In case any is currently being played (For eksample weapon fire, reload etc) //Currently only have a die animation montage, so dont need to do this //Play the death animation float deathAnimationLength = PlayAnimMontage(deathAnimation, 1.0f, NAME_None); //If the death animation was successfully played if (deathAnimationLength > 0.0f) { FTimerHandle onDeathTimerHandle; GetWorldTimerManager().SetTimer(onDeathTimerHandle, this, &AFPSGCharacter::onDeathAnimation, FMath::Min(0.1f, deathAnimationLength), false); //GetWorldTimerManager().SetTimer(onDeathTimerHandle, this, &AFPSGCharacter::onDeathAnimation, deathAnimationLength / 2.0f, false); } else { onDeathAnimation(); } } }
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(); } }