Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ASprunchEntity::PlayFootstep(uint8 FootNum) {
- if (GetWorld()->TimeSeconds - LastFootstepTime < 0.1f) {
- return;
- }
- UParticleSystem* FootStepEffect = DefaultFootstepEffect;
- float MaxParticleDist = 1500.f;
- USoundBase* FootstepSoundToPlay = DefaultFootstepSound;
- static FName NAME_FootstepTrace(TEXT("FootstepTrace"));
- FCollisionQueryParams QueryParams(NAME_FootstepTrace, false, this);
- QueryParams.bReturnPhysicalMaterial = true;
- QueryParams.bTraceAsyncScene = true;
- float PawnRadius, PawnHalfHeight;
- GetCapsuleComponent()->GetScaledCapsuleSize(PawnRadius, PawnHalfHeight);
- const FVector LineTraceStart = GetCapsuleComponent()->GetComponentLocation();
- const float TraceDist = 40.0f + PawnHalfHeight;
- const FVector Down = FVector(0.f, 0.f, -TraceDist);
- FHitResult Hit(1.f);
- bool bBlockingHit = GetWorld()->LineTraceSingleByChannel(Hit, LineTraceStart, LineTraceStart + Down, GetCapsuleComponent()->GetCollisionObjectType(), QueryParams);
- if (bBlockingHit)
- {
- if (Hit.PhysMaterial.IsValid())
- {
- EPhysicalSurface SurfaceType = UPhysicalMaterial::DetermineSurfaceType(Hit.PhysMaterial.Get());
- USoundBase* NewFootStepSound = GetFootstepSoundForSurfaceType(SurfaceType, false);
- UParticleSystem* NewFootStepEffect = GetFootstepEffectForSurfaceType(SurfaceType, false);
- if (NewFootStepSound)
- {
- FootstepSoundToPlay = NewFootStepSound;
- }
- if (NewFootStepEffect)
- {
- FootStepEffect = NewFootStepEffect;
- }
- }
- }
- FootStepEffect = (GetVelocity().Size() > 500.f) ? FootStepEffect : NULL;
- if (IsPlayerControlled()) {
- UGameplayStatics::PlaySound2D(GetWorld(), FootstepSoundToPlay);
- }
- else {
- UGameplayStatics::SpawnSoundAtLocation(GetWorld(), FootstepSoundToPlay, Hit.ImpactPoint, FRotator(90.f,0,0));
- }
- if (FootStepEffect && GetMesh() && (GetWorld()->GetTimeSeconds() - GetMesh()->LastRenderTime < 0.05f)
- && (GetLocalViewer() || (GetCachedScalabilityCVars().DetailMode != 0)))
- {
- FVector EffectLocation = GetActorLocation();
- EffectLocation.Z = EffectLocation.Z + 4.f - GetCapsuleComponent()->GetScaledCapsuleHalfHeight();
- UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), FootStepEffect, EffectLocation, GetActorRotation(), true);
- }
- LastFoot = FootNum;
- LastFootstepTime = GetWorld()->TimeSeconds;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement