Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. void ASprunchEntity::PlayFootstep(uint8 FootNum) {
  2. if (GetWorld()->TimeSeconds - LastFootstepTime < 0.1f) {
  3. return;
  4. }
  5.  
  6. UParticleSystem* FootStepEffect = DefaultFootstepEffect;
  7. float MaxParticleDist = 1500.f;
  8. USoundBase* FootstepSoundToPlay = DefaultFootstepSound;
  9.  
  10. static FName NAME_FootstepTrace(TEXT("FootstepTrace"));
  11. FCollisionQueryParams QueryParams(NAME_FootstepTrace, false, this);
  12. QueryParams.bReturnPhysicalMaterial = true;
  13. QueryParams.bTraceAsyncScene = true;
  14. float PawnRadius, PawnHalfHeight;
  15. GetCapsuleComponent()->GetScaledCapsuleSize(PawnRadius, PawnHalfHeight);
  16. const FVector LineTraceStart = GetCapsuleComponent()->GetComponentLocation();
  17. const float TraceDist = 40.0f + PawnHalfHeight;
  18. const FVector Down = FVector(0.f, 0.f, -TraceDist);
  19.  
  20. FHitResult Hit(1.f);
  21. bool bBlockingHit = GetWorld()->LineTraceSingleByChannel(Hit, LineTraceStart, LineTraceStart + Down, GetCapsuleComponent()->GetCollisionObjectType(), QueryParams);
  22.  
  23. if (bBlockingHit)
  24. {
  25. if (Hit.PhysMaterial.IsValid())
  26. {
  27. EPhysicalSurface SurfaceType = UPhysicalMaterial::DetermineSurfaceType(Hit.PhysMaterial.Get());
  28. USoundBase* NewFootStepSound = GetFootstepSoundForSurfaceType(SurfaceType, false);
  29. UParticleSystem* NewFootStepEffect = GetFootstepEffectForSurfaceType(SurfaceType, false);
  30. if (NewFootStepSound)
  31. {
  32. FootstepSoundToPlay = NewFootStepSound;
  33. }
  34. if (NewFootStepEffect)
  35. {
  36. FootStepEffect = NewFootStepEffect;
  37. }
  38. }
  39. }
  40.  
  41. FootStepEffect = (GetVelocity().Size() > 500.f) ? FootStepEffect : NULL;
  42. if (IsPlayerControlled()) {
  43. UGameplayStatics::PlaySound2D(GetWorld(), FootstepSoundToPlay);
  44. }
  45. else {
  46. UGameplayStatics::SpawnSoundAtLocation(GetWorld(), FootstepSoundToPlay, Hit.ImpactPoint, FRotator(90.f,0,0));
  47. }
  48.  
  49. if (FootStepEffect && GetMesh() && (GetWorld()->GetTimeSeconds() - GetMesh()->LastRenderTime < 0.05f)
  50. && (GetLocalViewer() || (GetCachedScalabilityCVars().DetailMode != 0)))
  51. {
  52. FVector EffectLocation = GetActorLocation();
  53. EffectLocation.Z = EffectLocation.Z + 4.f - GetCapsuleComponent()->GetScaledCapsuleHalfHeight();
  54. UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), FootStepEffect, EffectLocation, GetActorRotation(), true);
  55. }
  56. LastFoot = FootNum;
  57. LastFootstepTime = GetWorld()->TimeSeconds;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement