c++ - 使用虚幻引擎 4 编程的平台游戏中的偏转问题

标签 c++ unreal-engine4 2d-games

我正在尝试使用虚幻引擎 4(4.22 版)编写一个简单的平台游戏,该游戏的 Action 非常准确。它从 Super Meat Boy 或 Celeste 等游戏中汲取了一些灵感。 我正在使用使用 UCharacterMovementComponent 的 APaperCharacter,但我对它不是很满意。 特别是我想避免在 UCharacterMovementComponent::PhysFalling() 方法中使用的偏转:

const FVector OldHitNormal = Hit.Normal;
    const FVector OldHitImpactNormal = Hit.ImpactNormal;        
    FVector Delta = ComputeSlideVector(Adjusted, 1.f - Hit.Time, OldHitNormal, Hit);

    // Compute velocity after deflection (only gravity component for RootMotion)
    if (subTimeTickRemaining > KINDA_SMALL_NUMBER && !bJustTeleported)
    {
      const FVector NewVelocity = (Delta / subTimeTickRemaining);
      Velocity = HasAnimRootMotion() && !CurrentRootMotion.HasOverrideVelocity() ? FVector(Velocity.X, Velocity.Y, NewVelocity.Z) : NewVelocity;
    }

我录制了一段视频,向您展示我想防止的行为:

https://www.youtube.com/watch?v=fko1aPl-Vdo

我正在考虑创建派生 UCharacterMovementComponent 的个人移动组件,以便覆盖 ComputeSlideVector() 方法,但我不知道这是否是解决此问题的最佳主意。 我想听听您的意见,我想知道我是否可以简单地通过编辑器更改一些参数来解决问题。

最佳答案

我最终决定创建我自己的派生自 UCharacterMovementComponent 的类。 我解决了我在覆盖 UCharacterMovementComponent::ComputeSlideVector() 方法的问题中描述的问题:

FVector UMyMovementComponent::ComputeSlideVector(const FVector& Delta, const float Time, const FVector& Normal, const FHitResult& Hit) const
{
    FVector Result = Super::ComputeSlideVector(Delta, Time, Normal, Hit);

    if (Hit.bBlockingHit)
    {
        float Angle = FVector::DotProduct(Hit.Normal, FVector::DownVector);
        if (Angle > KINDA_SMALL_NUMBER) // if the collision normal points downwards
        {
            Result.X = 0.0f;
        }
    }

    return Result;
}

关于c++ - 使用虚幻引擎 4 编程的平台游戏中的偏转问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57436257/

相关文章:

c++ - GetOwner() 导致虚幻编辑器崩溃

ubuntu - 无法在 ubuntu 20.04 上安装 vulkan

Java - 内存使用,了解渲染的工作原理

c++ 将类对象从main传递到类函数时出错?

c++ - 类方法在转换后丢失私有(private)修饰符

c++ - 函数式转换语法如何工作?

c++ - 想要一些文字在游戏中抹去自己

c++ - 错误 : ‘memset’ was not declared in this scope

c++ - 检查重叠时虚幻编辑器崩溃

macos - 如何在全屏游戏中隐藏扩展坞和菜单栏?