Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/164.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用虚幻引擎4编程的platformer游戏中的偏转问题_C++_Unreal Engine4_2d Games - Fatal编程技术网

C++ 使用虚幻引擎4编程的platformer游戏中的偏转问题

C++ 使用虚幻引擎4编程的platformer游戏中的偏转问题,c++,unreal-engine4,2d-games,C++,Unreal Engine4,2d Games,我正试图用虚幻引擎4(4.22版)编写一个简单的平台游戏,游戏的动作非常精确。它从《超级肉男孩》或《塞莱斯特》等游戏中获得了一些灵感。 我使用的是使用UCharacterMovementComponent的ApapPerCharacter,但我对它不是很满意。 我特别希望避免UCharacterMovementComponent::PhysFalling()方法中使用的偏移: 我录制了一段视频,向您展示我想要阻止的行为: 我正在考虑创建我的个人移动组件,该组件派生UCharacterMovem

我正试图用虚幻引擎4(4.22版)编写一个简单的平台游戏,游戏的动作非常精确。它从《超级肉男孩》或《塞莱斯特》等游戏中获得了一些灵感。 我使用的是使用UCharacterMovementComponent的ApapPerCharacter,但我对它不是很满意。 我特别希望避免UCharacterMovementComponent::PhysFalling()方法中使用的偏移:

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

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

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


重写组件是一件很简单的事情。如果你想完全控制角色的移动,你可能会遇到更多的问题来塑造内置的角色移动器。塞莱斯特的乐章是白手起家写的。一般来说,有很多类,特别是虚幻中的游戏类可以被覆盖,这很好,因为它可以让编写某些游戏变得可行,而无需从源代码构建。
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;
    }
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;
}