void ABaseCharacter::SetRagdollPhysics() { USkeletalMeshComponent* Mesh3P = GetMesh(); if (Mesh3P) { Mesh3P->SetCollisionProfileName(TEXT("Ragdoll")); } SetActorEnableCollision(true); if (!IsPendingKill() || Mesh3P || Mesh3P->GetPhysicsAsset()) { Mesh3P->SetAllBodiesSimulatePhysics(true); Mesh3P->SetSimulatePhysics(true); Mesh3P->WakeAllRigidBodies(); Mesh3P->bBlendPhysics = true; SetLifeSpan(TimeAfterDeathBeforeDestroy); } else { // Immediately hide the pawn TurnOff(); SetActorHiddenInGame(true); SetLifeSpan(1.0f); } UCharacterMovementComponent* CharacterComp = Cast<UCharacterMovementComponent>(GetMovementComponent()); if (CharacterComp) { CharacterComp->StopMovementImmediately(); CharacterComp->DisableMovement(); CharacterComp->SetComponentTickEnabled(false); } }
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); } }
// Called every frame void AMissleProjectile::Tick( float DeltaTime ) { Super::Tick(DeltaTime); if (TargetActor != nullptr) { NotifyTarget(this); FVector WantedDir = (TargetActor->GetActorLocation() - GetActorLocation()).GetSafeNormal(); WantedDir += TargetActor->GetVelocity() * WantedDir.Size() / MissleMovement->MaxSpeed; MissleMovement->Velocity += WantedDir * MissleMovement->InitialSpeed * 100.0f * DeltaTime; MissleMovement->Velocity = MissleMovement->Velocity.GetSafeNormal() * MissleMovement->MaxSpeed; FVector Dis = GetActorLocation() - (TargetActor->GetActorLocation()); if (Dis.Size() < 5) { Server_Explode(TargetActor, BP_Explosion.GetDefaultObject(), Damage); } } else { NotifyTarget(nullptr); SetLifeSpan(1.0f); } }
void Bomb::OnBeforeUpdate() { World& world = World::GetInstance(); Actor collisionFire; if(world.GetFireManager()->IsColliding(*this, &collisionFire)) { SetLifeSpan(0); } if(CanDelete() && CanTriggerExplosion()) { std::shared_ptr<BombExplodedEvent> bombExplosionEvent(new BombExplodedEvent(GetId(), m_position)); world.GetEventManager()->QueueEvent(bombExplosionEvent); m_bCanTriggerExplosion = false; } if(CanRenderNextFrame()) { m_animation.NextFrame(); m_nextFrameWait = BOMB_NEXTFRAME_WAIT; } else { m_nextFrameWait = std::max<uint32_t>(0, m_nextFrameWait - 1); } }
void AZanshinBasicArrow::OnHit(AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) { if (Role < ROLE_Authority){ return; } if (OtherActor != nullptr) { AZanshinCharacter* Enemy = Cast<AZanshinCharacter>(OtherActor); if (Enemy != nullptr && MyPawn != nullptr && MyPawn->GetTeam() != Enemy->GetTeam()) { NetMulticast_SpecialPower(Enemy, Hit); //Add all feedback to the player here. if (!Enemy->bIsDead) { MyPawn->AddPlayerFeedback_HitEnemy(); Enemy->AddPlayerFeedback_ReceiveHit(); StuckOnPlayer(OtherComp); } } else if (OtherActor != this) { NetMulticast_SpecialPowerHitEnvironment(Hit); } } SetHitPosition(Hit.ImpactPoint); SetLifeSpan(LifeSpan); ArrowAudioComponent->Activate(false); ArrowAudioComponent->bAutoActivate = false; ArrowAudioComponent->Stop(); }
Bomb::Bomb() : m_spriteSheet(nullptr), m_nextFrameWait(BOMB_NEXTFRAME_WAIT), m_bCanTriggerExplosion(true) { SetLifeSpan(BOMB_LIFESPAN); }
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 AEmitter::OnParticleSystemFinished(UParticleSystemComponent* FinishedComponent) { if (bDestroyOnSystemFinish) { SetLifeSpan(0.0001f); } bCurrentlyActive = false; }
static void create() { germ::create(); SetId("cold"); SetType("cold"); SetCommunicable(40); SetCure(20); SetLifeSpan(60); }
Fire::Fire() : Actor(), m_spriteSheet(nullptr), m_nextFrameWait(FIRE_NEXTFRAME_WAIT), m_bCanTriggerFireExtinguished(true) { SetLifeSpan(FIRE_LIFESPAN); }
void AEnemy::SpawnNew() { FVector location = FVector(FMath::RandRange(-700.0f, 1100.0f), FMath::RandRange(-1100.0f, 1100.0f), 300.0f); AEnemy* newEnemy = (AEnemy*) GetWorld()->SpawnActor(AEnemy::StaticClass(), &location); SetLifeSpan(0.1f); }
void ARPGProjectile::DisableAndDestroy() { SetActorHiddenInGame(true); MovementComp->StopMovementImmediately(); // give clients some time to show explosion SetLifeSpan( 1.0f ); }
// Called when the game starts or when spawned void APreprekaCPP::BeginPlay() { Super::BeginPlay(); /*Stavimo duzinu zivota ovde jer nam se editor rusi ako ga stavimo u konstrukotr*/ SetLifeSpan(20.f); }
// Called every frame void AHunterProjectile::Tick( float DeltaTime ) { Super::Tick( DeltaTime ); if (GetAttachParentActor()) { return; } FVector deltaMove = DeltaTime * m_velocity; FVector newLocation = GetActorLocation() + deltaMove; SetActorLocation(newLocation, false); AActor *hitActor = FindHitActor(); if (hitActor) { ABasicAIAgent *hitAgent = Cast<ABasicAIAgent>(hitActor); bool doAttach = false; UBoxComponent *attachBox = nullptr; if (hitAgent && hitAgent->m_teamID == TEAM_CALVES) { attachBox = hitAgent->GetSpearBox(); hitAgent->ModifyHealth(-m_projectileDamage); doAttach = true; } else if (ATP_TopDownCharacter *playerChar = Cast<ATP_TopDownCharacter>(hitActor)) { attachBox = playerChar->GetSpearBox(); playerChar->SpearHit(); doAttach = true; } if (attachBox) { FVector boxExtents = attachBox->GetScaledBoxExtent(); FVector boxOrigin = attachBox->GetComponentLocation(); FBox box(boxOrigin - boxExtents, boxOrigin + boxExtents); FVector attachPos = FMath::RandPointInBox(box); SetActorLocation(attachPos); } if (doAttach) { // Destroy(); SetLifeSpan(20.0f); GetRootComponent()->AttachTo(hitActor->GetRootComponent(), NAME_None, EAttachLocation::KeepWorldPosition); OnProjectileHit(); } } }
void ALonelyMenCharacter::SetRagDollPhysics() { bool bInRagdoll = false; if (IsPendingKill()) { bInRagdoll = false; } else if (!GetMesh() || !GetMesh()->GetPhysicsAsset()) { bInRagdoll = false; } else { //init physics GetMesh()->SetAllBodiesSimulatePhysics(true); GetMesh()->SetSimulatePhysics(true); GetMesh()->WakeAllRigidBodies(); GetMesh()->bBlendPhysics = true; bInRagdoll = true; } GetCharacterMovement()->StopMovementImmediately(); GetCharacterMovement()->DisableMovement(); GetCharacterMovement()->SetComponentTickEnabled(false); if (!bInRagdoll) { //hide and set short lifespan TurnOff(); SetActorHiddenInGame(true); SetLifeSpan(1.0f); } else { float beginTime, endTime; GetMesh()->AnimScriptInstance->GetCurrentActiveMontage()->GetSectionStartAndEndTime(0, beginTime, endTime); SetLifeSpan(endTime - endTime*0.4); } }
void AProjectile::BeginPlay() { Super::BeginPlay(); SetLifeSpan(25.f); if (IsValid(homingTarget) && !homingTarget->IsAlive()) Destroy(); }
void AProjectile::PostInitializeComponents() { Super::PostInitializeComponents(); ProjectileMovement->OnProjectileStop.AddDynamic( this, &AProjectile::OnCollide ); Collision->MoveIgnoreActors.Add( Instigator ); SetLifeSpan( 7.0f ); }
void AZanshinBasicArrow::BeginPlay() { Super::BeginPlay(); MaxRadius = TipSphereComponent->GetScaledSphereRadius(); TipSphereComponent->SetSphereRadius(2.5f); SetLifeSpan(LifeSpan); }
void AShooterCharacter::SetRagdollPhysics() { bool bInRagdoll = false; USkeletalMeshComponent* Mesh3P = GetMesh(); if (IsPendingKill()) { bInRagdoll = false; } else if (!Mesh3P || !Mesh3P->GetPhysicsAsset()) { bInRagdoll = false; } else { Mesh3P->SetAllBodiesSimulatePhysics(true); Mesh3P->SetSimulatePhysics(true); Mesh3P->WakeAllRigidBodies(); Mesh3P->bBlendPhysics = true; bInRagdoll = true; } UCharacterMovementComponent* CharacterComp = Cast<UCharacterMovementComponent>(GetMovementComponent()); if (CharacterComp) { CharacterComp->StopMovementImmediately(); CharacterComp->DisableMovement(); CharacterComp->SetComponentTickEnabled(false); } if (!bInRagdoll) { // Immediately hide the pawn TurnOff(); SetActorHiddenInGame(true); SetLifeSpan(1.0f); } else { SetLifeSpan(10.0f); } }
// Called when the game starts or when spawned void AImpactEffect::PostInitializeComponents() { Super::PostInitializeComponents(); SetLifeSpan(1); // rotate the decal in the direction of the normal vector of the HitResult with random roll rotation RandomDecalRotation = HitResult.Normal.Rotation(); RandomDecalRotation.Roll = FMath::RandRange(-180.0f, 180.0f); UWorld* World = GetWorld(); if (World && HitResult.PhysMaterial.IsValid()) { switch (HitResult.PhysMaterial->SurfaceType) { case SURFACE_DEFAULT: { //GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, "Default"); if (DefaultFX) { UGameplayStatics::SpawnEmitterAtLocation(World, DefaultFX, HitResult.ImpactPoint, RandomDecalRotation); } if (DefaultSound) { UGameplayStatics::SpawnSoundAtLocation(World, DefaultSound, HitResult.ImpactPoint); } if (DefaultDecalMat && HitResult.Component.IsValid()) { UGameplayStatics::SpawnDecalAttached(DefaultDecalMat, FVector(DecalSize, DecalSize, 1.0f), HitResult.Component.Get(), HitResult.BoneName, HitResult.ImpactPoint, RandomDecalRotation, EAttachLocation::KeepWorldPosition, DecalLifeSpan); } break; } case SURFACE_HEAD: case SURFACE_BODY: case SURFACE_LIMB: { //GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, "Flesh " + HitResult.BoneName.ToString()); if (FleshFX) { UGameplayStatics::SpawnEmitterAtLocation(World, FleshFX, HitResult.ImpactPoint, RandomDecalRotation); } if (FleshSound) { UGameplayStatics::SpawnSoundAtLocation(World, FleshSound, HitResult.ImpactPoint); } break; } } } }
void ARPGProjectile::PostInitializeComponents() { Super::PostInitializeComponents(); //MovementComp->OnProjectileStop.AddDynamic(this, &ARPGProjectile::OnImpact); CollisionComp->MoveIgnoreActors.Add(Instigator); SetLifeSpan(10); MyController = Cast<ARPGPlayerController>(GetInstigatorController()); }
Fire::Fire(float x, float y) : Actor(x, y), m_spriteSheet(nullptr), m_nextFrameWait(FIRE_NEXTFRAME_WAIT), m_bCanTriggerFireExtinguished(true) { SetLifeSpan(FIRE_LIFESPAN); #ifdef _DEBUG std::cout << "Creating the Fire with ID " << GetId() << std::endl;; #endif }
void ABomb::ApplyExplosionDamage() { for ( TActorIterator<ANetGameCPPCharacter> aItr(GetWorld()); aItr; ++aItr ) { if ( GetDistanceTo(*aItr) <= ExplosionRadius) UGameplayStatics::ApplyDamage(*aItr, ExplosionDamage, GetInstigatorController(), this, UDamageType::StaticClass()); } OnExplosion(); SetLifeSpan(2.0f); }
Bomb::Bomb(float x, float y) : Actor(x, y), m_spriteSheet(nullptr), m_nextFrameWait(BOMB_NEXTFRAME_WAIT), m_bCanTriggerExplosion(true) { SetLifeSpan(BOMB_LIFESPAN); #ifdef _DEBUG std::cout << "Creating the Bomb with ID " << GetId() << std::endl;; #endif }
void UDecalComponent::SetFadeOut(float StartDelay, float Duration, bool DestroyOwnerAfterFade /*= true*/) { float FadeDurationScale = CVarDecalFadeDurationScale.GetValueOnGameThread(); FadeDurationScale = (FadeDurationScale <= SMALL_NUMBER) ? 0.0f : FadeDurationScale; FadeStartDelay = StartDelay * FadeDurationScale; FadeDuration = Duration * FadeDurationScale; bDestroyOwnerAfterFade = DestroyOwnerAfterFade; SetLifeSpan(FadeStartDelay + FadeDuration); MarkRenderStateDirty(); }
void ADwarfGold::OnPickedUp(ADwarfPlayerController* DwarfController) { if (bCollected) { return; } ADwarfGameState* DwarfGameState = GetWorld()->GetGameState<ADwarfGameState>(); DwarfGameState->CoinsCollected++; SetActorHiddenInGame(true); SetLifeSpan(0.1f); bCollected = true; }
void AShooterProjectile::DisableAndDestroy() { UAudioComponent* ProjAudioComp = FindComponentByClass<UAudioComponent>(); if (ProjAudioComp && ProjAudioComp->IsPlaying()) { ProjAudioComp->FadeOut(0.1f, 0.f); } MovementComp->StopMovementImmediately(); // give clients some time to show explosion SetLifeSpan( 2.0f ); }
void ANimModCharacter::SetRagdollPhysics() { bool bInRagdoll = false; if (IsPendingKill()) { bInRagdoll = false; } else if (!GetMesh() || !GetMesh()->GetPhysicsAsset()) { bInRagdoll = false; } else { // initialize physics/etc GetMesh()->SetAllBodiesSimulatePhysics(true); GetMesh()->SetSimulatePhysics(true); GetMesh()->WakeAllRigidBodies(); GetMesh()->bBlendPhysics = true; bInRagdoll = true; } GetCharacterMovement()->StopMovementImmediately(); GetCharacterMovement()->DisableMovement(); GetCharacterMovement()->SetComponentTickEnabled(false); if (!bInRagdoll) { // hide and set short lifespan TurnOff(); SetActorHiddenInGame(true); SetLifeSpan(1.0f); } else { SetLifeSpan(10.0f); } }
void AZanshinBasicArrow::CreateAnimationArrowPickup(USkeletalMeshComponent* Mesh, FName SocketName) { AnimationArrow->SetVisibility(true); FlyingArrow->SetVisibility(false); ProjectileMovement->DestroyComponent(); DeactivateTrails(); SetLifeSpan(0); RootComponent->AttachTo(Mesh, SocketName, EAttachLocation::SnapToTarget); }
void AShooterProjectile::PostInitializeComponents() { Super::PostInitializeComponents(); MovementComp->OnProjectileStop.AddDynamic(this, &AShooterProjectile::OnImpact); CollisionComp->MoveIgnoreActors.Add(Instigator); AShooterWeapon_Projectile* OwnerWeapon = Cast<AShooterWeapon_Projectile>(GetOwner()); if (OwnerWeapon) { OwnerWeapon->ApplyWeaponConfig(WeaponConfig); } SetLifeSpan( WeaponConfig.ProjectileLife ); MyController = GetInstigatorController(); }