六一的部落格


关关难过关关过,前路漫漫亦灿灿。



Homework / Pickup, Impact Sounds


说明

  1. 拾取健康补给和弹药补给播放不同音效
  2. 步枪击中NPC, 金属材质音效, 击中默认音效
  3. 榴弹击中默认音效

课程中将步枪击中金属音效给了地板


创建Sound Class资产

  • SC_Pickup
  • SC_Impact

创建Sound Cue资产

创建文件夹 Content/Sounds/Pickup

ExternalContent/Sounds/ Content/Sounds/ 分组 声音衰减
步枪默认击中 Impacts/wav sw_Impt_AK_Default_01 - 16 SCue_ImpactDefault Weapon/Rifle SC_Impact BulletImpacts
步枪击中NPC Impacts/wav sw_Impt_AK_Flesh_01 - 10 SCue_ImpactFlesh Weapon/Rifle SC_Impact BulletImpacts
步枪击中金属 Impacts/wav sw_Impt_AK_Mtl_01 - 16 SCue_ImpactMetal Weapon/Rifle SC_Impact BulletImpacts
发射器击中 Impacts/wav sw_Impt_Launcher_Close_01 - 05 SCue_ImpactLauncher Weapon/Launcher SC_Impact Explosion
拾取弹药补给 Pickups/wav sw_Pickup_Ammo SCue_PickupAmmo Pickup SC_Pickup Pickups
拾取健康补给 Pickups/wav sw_Pickup_Health SCue_PickupHealth Pickup SC_Pickup Pickups

创建并设置物理材质

  1. 创建PhysMat_Metal


  2. 在场景中添加球体, 并为之设置物理材质

    • Place Actors > Shapes > Sphere

    • 设置金属物理材质, 测试用


  3. 为地板设置物理材质



回顾特效之于物理材质

  1. STUCoreTypes.h中定义有结构体FImpactData, 存放印花和特效的对应关系

    目前步枪和榴弹发射器各有一种印花
  2. 榴弹和步枪均拥有自定义组件STUWeaponFXComponent, 该组件存放物理材质和FImpactData的对应关系, 以及默认特效信息
  3. 当步枪和榴弹有击中目标, 便调用STUWeaponFXComponent接口PlayImpactFX播放特效和生成印花
  4. PlayImpactFX中会查询与材质对应的特效信息, 采用之

修改FImpactData, 添加音效属性

ShootThemUp: STUCoreTypes.h

1class USoundCue;
2
3UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
4USoundCue *ImpactSound; /* Sound */

实现击中音效

ShootThemUp: Weapon/Components/STUWeaponFXComponent.cpp

1#include "Sound/SoundCue.h"
2
3// PlayImpactFX
4UGameplayStatics::PlaySoundAtLocation(GetWorld(), ImpactData.ImpactSound, Hit.ImpactPoint);

实现拾取补给音效

  1. 添加属性: 保存音效

    protected

    ShootThemUp: Pickups/STUBasePickup.h

    1class USoundCue;
    2
    3UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
    4USoundCue *PickupSound;
  2. 拾取时播放

    ShootThemUp: Pickups/STUBasePickup.cpp

    1#include "Sound/SoundCue.h"
    2#include "Kismet/GameplayStatics.h"
    3
    4// PickupWasTaken
    5UGameplayStatics::PlaySoundAtLocation(GetWorld(), PickupSound, GetActorLocation());

设置


物理材质和音效的对应关系

  1. 榴弹

    只有默认配置


  2. 步枪


    增加金属材质



补给音效

Pickup Sound
BP_STUAmmoPickup SCue_PickupAmmo
BP_STUHealthPickup SCue_PickupHealth

查看

  1. 测试击中音效时, 可以关闭武器音量

    SC_Weapon
  2. 测试拾取健康补给音效时, 使能NPC行为树

    之前对伤害来源做了判断, 无法使用无主伤害

拾取补给和击中音效


Homework / Pickup, Impact Sounds


说明

  1. 拾取健康补给和弹药补给播放不同音效
  2. 步枪击中NPC, 金属材质音效, 击中默认音效
  3. 榴弹击中默认音效

课程中将步枪击中金属音效给了地板


创建Sound Class资产

  • SC_Pickup
  • SC_Impact

创建Sound Cue资产

创建文件夹 Content/Sounds/Pickup

ExternalContent/Sounds/ Content/Sounds/ 分组 声音衰减
步枪默认击中 Impacts/wav sw_Impt_AK_Default_01 - 16 SCue_ImpactDefault Weapon/Rifle SC_Impact BulletImpacts
步枪击中NPC Impacts/wav sw_Impt_AK_Flesh_01 - 10 SCue_ImpactFlesh Weapon/Rifle SC_Impact BulletImpacts
步枪击中金属 Impacts/wav sw_Impt_AK_Mtl_01 - 16 SCue_ImpactMetal Weapon/Rifle SC_Impact BulletImpacts
发射器击中 Impacts/wav sw_Impt_Launcher_Close_01 - 05 SCue_ImpactLauncher Weapon/Launcher SC_Impact Explosion
拾取弹药补给 Pickups/wav sw_Pickup_Ammo SCue_PickupAmmo Pickup SC_Pickup Pickups
拾取健康补给 Pickups/wav sw_Pickup_Health SCue_PickupHealth Pickup SC_Pickup Pickups

创建并设置物理材质

  1. 创建PhysMat_Metal


  2. 在场景中添加球体, 并为之设置物理材质

    • Place Actors > Shapes > Sphere

    • 设置金属物理材质, 测试用


  3. 为地板设置物理材质



回顾特效之于物理材质

  1. STUCoreTypes.h中定义有结构体FImpactData, 存放印花和特效的对应关系

    目前步枪和榴弹发射器各有一种印花
  2. 榴弹和步枪均拥有自定义组件STUWeaponFXComponent, 该组件存放物理材质和FImpactData的对应关系, 以及默认特效信息
  3. 当步枪和榴弹有击中目标, 便调用STUWeaponFXComponent接口PlayImpactFX播放特效和生成印花
  4. PlayImpactFX中会查询与材质对应的特效信息, 采用之

修改FImpactData, 添加音效属性

ShootThemUp: STUCoreTypes.h

1class USoundCue;
2
3UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
4USoundCue *ImpactSound; /* Sound */

实现击中音效

ShootThemUp: Weapon/Components/STUWeaponFXComponent.cpp

1#include "Sound/SoundCue.h"
2
3// PlayImpactFX
4UGameplayStatics::PlaySoundAtLocation(GetWorld(), ImpactData.ImpactSound, Hit.ImpactPoint);

实现拾取补给音效

  1. 添加属性: 保存音效

    protected

    ShootThemUp: Pickups/STUBasePickup.h

    1class USoundCue;
    2
    3UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
    4USoundCue *PickupSound;
  2. 拾取时播放

    ShootThemUp: Pickups/STUBasePickup.cpp

    1#include "Sound/SoundCue.h"
    2#include "Kismet/GameplayStatics.h"
    3
    4// PickupWasTaken
    5UGameplayStatics::PlaySoundAtLocation(GetWorld(), PickupSound, GetActorLocation());

设置


物理材质和音效的对应关系

  1. 榴弹

    只有默认配置


  2. 步枪


    增加金属材质



补给音效

Pickup Sound
BP_STUAmmoPickup SCue_PickupAmmo
BP_STUHealthPickup SCue_PickupHealth

查看

  1. 测试击中音效时, 可以关闭武器音量

    SC_Weapon
  2. 测试拾取健康补给音效时, 使能NPC行为树

    之前对伤害来源做了判断, 无法使用无主伤害