【问题标题】:Deflection issue in platformer game programmed with Unreal Engine 4使用虚幻引擎 4 编程的平台游戏中的偏转问题
【发布时间】:2019-12-17 13:28:39
【问题描述】:

我正在尝试使用虚幻引擎 4(4.22 版)编写一个具有非常精确动作的简单平台游戏。它从 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() 方法,但我不知道这是否是解决此问题的最佳主意。 我想听听您的意见,我想知道我是否可以简单地解决编辑器更改某些参数的问题。

【问题讨论】:

  • 如果你想完全控制角色移动,覆盖组件真的很简单,你可能会在尝试塑造内置角色移动器时遇到更多问题。 Celeste 的乐章是从零开始写的。此外,通常还有大量的类,尤其是 Unreal 中可以覆盖的游戏类,这非常棒,因为它可以使编写某些游戏变得可行,而无需从源代码构建。

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


【解决方案1】:

我最终决定创建自己的从 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;
}

【讨论】:

    猜你喜欢
    • 2020-06-08
    • 2020-09-01
    • 2020-11-18
    • 2015-09-24
    • 2020-02-23
    • 1970-01-01
    • 2018-07-29
    • 2018-10-16
    • 2015-01-13
    相关资源
    最近更新 更多