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



我正在尝试使用虚幻引擎4(4.22版本(编写一款具有非常精确移动的简单平台游戏。它从Super Meat Boy或Celeste等游戏中获得了一些灵感。 我正在使用使用UCharacterMovementComponent的APaperCharacter,但我对它不是很满意。 特别是我想避免UCharacterMovementComponent::P hysFalling((方法中使用的偏转:

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;
}

最新更新