Announcement

Collapse
No announcement yet.

Impact Sounds for Physical Materials on Static Meshes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Impact Sounds for Physical Materials on Static Meshes

    Hello guys!

    I have been playing with Physical Materials and footstep sounds.

    For each material on my map I am adding a physical material (on the material editor) to get custom footstep sounds for things like Wood, Metal, Rocks, and so on.

    Everything works like a charm, however, I am trying to get custom hit sounds whenever the player shoots at static meshes.

    In example, I have a small house on my map, which is a single static mesh with various materials applied (3dsmax multi material/sub object). As I said, each material has a different physical material applied. In example, the floor is wooden, and the staircase on the entrance is of metal. So it works perfectly for the footstep.

    However, I wanted that whenever the player shoots at the wooden part, it plays a wooden hit bullet sound effect.

    By seeing the wood physical material propeties, there is a field for Impact Sound. I already added my custom wooden bullet impact sound there (and saved the package).

    However, nothing happens whenever I shoot the wooden part of the house, it does not play the impact sound effect. As my guns are all projectile guns, the impact sound I hear is the Projectile ExplosionSound (I also have a custom sound cue for this), but the wooden physical material impact sound (which I already added the sound cue there), does not play.

    By searching on the classes, I have found this function of UTWeap_PhysicsGun

    Code:
    simulated function StartFire(byte FireModeNum)
    {
        local vector                    StartShot, EndShot, PokeDir;
        local vector                    HitLocation, HitNormal, Extent;
        local actor                        HitActor;
        local float                        HitDistance;
        local Quat                        PawnQuat, InvPawnQuat, ActorQuat;
        local TraceHitInfo                HitInfo;
        local SkeletalMeshComponent        SkelComp;
        local Rotator                    Aim;
        local PhysAnimTestActor            PATActor;
        local StaticMeshComponent HitComponent;
        local KActorFromStatic NewKActor;
    
        if ( Role < ROLE_Authority )
            return;
    
        // Do ray check and grab actor
        StartShot    = Instigator.GetWeaponStartTraceLocation();
        Aim            = GetAdjustedAim( StartShot );
        EndShot        = StartShot + (10000.0 * Vector(Aim));
        Extent        = vect(0,0,0);
        HitActor    = Trace(HitLocation, HitNormal, EndShot, StartShot, True, Extent, HitInfo, TRACEFLAG_Bullet);
        HitDistance = VSize(HitLocation - StartShot);
    
        HitComponent = StaticMeshComponent(HitInfo.HitComponent);
        if ( (HitComponent != None) ) 
        {
            if(HitInfo.PhysMaterial != none)
            {
                if(HitInfo.PhysMaterial.ImpactSound != none)
                {
                    PlaySound(HitInfo.PhysMaterial.ImpactSound,,,,HitLocation);
                }
    
                if(HitInfo.PhysMaterial.ImpactEffect != none)
                {
                    WorldInfo.MyEmitterPool.SpawnEmitter(HitInfo.PhysMaterial.ImpactEffect, HitLocation, rotator(HitNormal), none);
                }
            }
    
            if( HitComponent.CanBecomeDynamic() )
            {
                NewKActor = class'KActorFromStatic'.Static.MakeDynamic(HitComponent);
                if ( NewKActor != None )
                {
                    HitActor = NewKActor;
                }
            }
        }
    So I tried to add this function inside the UTProjectile class function

    Code:
    simulated function SpawnExplosionEffects(vector HitLocation, vector HitNormal)
    
    local TraceHitInfo                HitInfo;
    local StaticMeshComponent HitComponent;
    HitComponent = StaticMeshComponent(HitInfo.HitComponent);
    
    .
    .
    .
    .
    .
    .
    .
    .
    .
    
            if (ExplosionSound != None && !bSuppressSounds)
            {
                PlaySound(ExplosionSound, true);
    
        if ( (HitComponent != None) ) 
        {
            if(HitInfo.PhysMaterial != none)
            {
                if(HitInfo.PhysMaterial.ImpactSound != none)
                {
                    PlaySound(HitInfo.PhysMaterial.ImpactSound,,,,HitLocation);
                }
    
                if(HitInfo.PhysMaterial.ImpactEffect != none)
                {
                    WorldInfo.MyEmitterPool.SpawnEmitter(HitInfo.PhysMaterial.ImpactEffect, HitLocation, rotator(HitNormal), none);
                }
            }
    
            if( HitComponent.CanBecomeDynamic() )
            {
                NewKActor = class'KActorFromStatic'.Static.MakeDynamic(HitComponent);
                if ( NewKActor != None )
                {
                    HitActor = NewKActor;
                }
            }
        }
    
            }
    But the only sound I hear is the Projectile Explosion Sound, not the Physical Material Impact Sound.

    Any help?
    https://sites.google.com/view/udkultimate/

Working...
X