使用 Unreal Engine 4 编程的平台游戏中的偏转问题
Deflection issue in platformer game programmed with Unreal Engine 4
我正在尝试使用 Unreal Engine 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() 方法,但我不知道这是否是解决此问题的最佳主意。
我想听听你的意见,我想知道我是否可以简单地通过编辑器更改一些参数来解决问题。
我最终决定创建自己的 class 从 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;
}
我正在尝试使用 Unreal Engine 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() 方法,但我不知道这是否是解决此问题的最佳主意。 我想听听你的意见,我想知道我是否可以简单地通过编辑器更改一些参数来解决问题。
我最终决定创建自己的 class 从 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;
}