六一的部落格


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




说明

MatineeCameraShake 已被 LegacyCameraShake 取代


创建抖动蓝图类

Content/VFX

右键, Blueprint Class


选择基类 LegacyCameraSh , 命名为BP_DamageCameraShake


开箱即用的解决方案让我们可以很快的实现抖动效果

双击打开, 查看细节面板

  • Oscillation > Oscillation Duration : 摄像机晃动的时间
  • 绕各轴的振动, 如 Pitch, Yaw, 和 Roll



测试抖动类


为摄像机添加抖动

BP_STUPlayerController > EventGraph

添加节点 GetPlayerCameraManager , 作为节点 StartCameraShake 的输入; 在Tick函数中调用; 设置抖动类为BP_DamageCameraShake



设置抖动时长

BP_DamageCameraShake

  • 设置 Oscillation Duration 为0.2
  • 添加垂直方向 Pitch 和水平方向 Yaw 的抖动


  • 如果添加摄像机旋转 Roll 抖动, 有地板晃动效果, 暂不需要
  • 抖动参数由设计师提供

断开摄像机抖动

BP_STUPlayerController > EventGraph


游戏角色受伤时为摄像机添加抖动


添加依赖模块GameplayCameras

ShootThemUp: ShootThemUp.Build.cs

 1PublicDependencyModuleNames.AddRange(new string[]
 2{
 3    "Core",
 4    "CoreUObject",
 5    "Engine",
 6    "InputCore",
 7    "Niagara",
 8    "PhysicsCore",
 9    "GameplayCameras"
10});

添加抖动类属性

ShootThemUp: Components/STUHealthComponent.h

protected

1class UCameraShakeBase;
2
3UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
4TSubclassOf<UCameraShakeBase> CameraShake;

添加接口: 使摄像机抖动

ShootThemUp: Components/STUHealthComponent.h

private

1void PlayCameraShake(); 

受到伤害时调用

ShootThemUp: Components/STUHealthComponent.cpp

1// OnTakeAnyDamage
2PlayCameraShake();

要求游戏角色未死亡

 1#include "GameFramework/Pawn.h"
 2#include "GameFramework/PlayerController.h"
 3#include "LegacyCameraShake.h"
 4
 5void USTUHealthComponent::PlayCameraShake()
 6{
 7    if (IsDead()) return;
 8
 9    const auto Player = Cast<APawn>(GetOwner());
10    if (!Player) return;
11
12    const auto Controller = Player->GetController<APlayerController>();
13    if (!Controller || !Controller->PlayerCameraManager) return;
14
15    Controller->PlayerCameraManager->StartCameraShake(CameraShake);
16}

查看

BP_BaseCharacter

设置抖动类为BP_DamageCameraShake


选中伤害球, 调整伤害数值

Details > Damage , 设为0.5



当受到其他游戏角色的射击伤害时, 有所察觉


游戏角色受到伤害时为摄像机添加抖动



说明

MatineeCameraShake 已被 LegacyCameraShake 取代


创建抖动蓝图类

Content/VFX

右键, Blueprint Class


选择基类 LegacyCameraSh , 命名为BP_DamageCameraShake


开箱即用的解决方案让我们可以很快的实现抖动效果

双击打开, 查看细节面板

  • Oscillation > Oscillation Duration : 摄像机晃动的时间
  • 绕各轴的振动, 如 Pitch, Yaw, 和 Roll



测试抖动类


为摄像机添加抖动

BP_STUPlayerController > EventGraph

添加节点 GetPlayerCameraManager , 作为节点 StartCameraShake 的输入; 在Tick函数中调用; 设置抖动类为BP_DamageCameraShake



设置抖动时长

BP_DamageCameraShake

  • 设置 Oscillation Duration 为0.2
  • 添加垂直方向 Pitch 和水平方向 Yaw 的抖动


  • 如果添加摄像机旋转 Roll 抖动, 有地板晃动效果, 暂不需要
  • 抖动参数由设计师提供

断开摄像机抖动

BP_STUPlayerController > EventGraph


游戏角色受伤时为摄像机添加抖动


添加依赖模块GameplayCameras

ShootThemUp: ShootThemUp.Build.cs

 1PublicDependencyModuleNames.AddRange(new string[]
 2{
 3    "Core",
 4    "CoreUObject",
 5    "Engine",
 6    "InputCore",
 7    "Niagara",
 8    "PhysicsCore",
 9    "GameplayCameras"
10});

添加抖动类属性

ShootThemUp: Components/STUHealthComponent.h

protected

1class UCameraShakeBase;
2
3UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
4TSubclassOf<UCameraShakeBase> CameraShake;

添加接口: 使摄像机抖动

ShootThemUp: Components/STUHealthComponent.h

private

1void PlayCameraShake(); 

受到伤害时调用

ShootThemUp: Components/STUHealthComponent.cpp

1// OnTakeAnyDamage
2PlayCameraShake();

要求游戏角色未死亡

 1#include "GameFramework/Pawn.h"
 2#include "GameFramework/PlayerController.h"
 3#include "LegacyCameraShake.h"
 4
 5void USTUHealthComponent::PlayCameraShake()
 6{
 7    if (IsDead()) return;
 8
 9    const auto Player = Cast<APawn>(GetOwner());
10    if (!Player) return;
11
12    const auto Controller = Player->GetController<APlayerController>();
13    if (!Controller || !Controller->PlayerCameraManager) return;
14
15    Controller->PlayerCameraManager->StartCameraShake(CameraShake);
16}

查看

BP_BaseCharacter

设置抖动类为BP_DamageCameraShake


选中伤害球, 调整伤害数值

Details > Damage , 设为0.5



当受到其他游戏角色的射击伤害时, 有所察觉