我正在尝试编程一个简单的平台游戏与非常准确的移动使用虚幻引擎4 (4.22版)。它从像超级肉食男孩或塞莱斯特这样的游戏中获得了一些灵感。我正在使用使用UCharacterMovementComponent的UCharacterMovementComponent,但我对它不太满意。特别是,我想避免在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()方法,但我不知道解决这个问题是否最好。我想要你的观点,我想知道我是否可以简单地解决这个问题,通过编辑改变一些参数。
发布于 2019-08-17 21:20:15
我最终决定创建从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;
}https://stackoverflow.com/questions/57436257
复制相似问题