UE floating pawn movement Bug Set location 导致速度异常发射

最近做传送门的时候发现一个很好玩的问题,当我通过Collsion触发带floatingPawnMovement的Pawn的SetActionLocation时会获得非常大的速度:



pawn直接弹射到宇宙了ಠ_ಠ

但是当我通过controller按键触发传送时 却没有这个问题


于是我看了下floatingPawnMovement代码 发现了问题所在
`void UFloatingPawnMovement::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
if (ShouldSkipUpdate(DeltaTime))
{
return;
}

Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

if (!PawnOwner || !UpdatedComponent)
{
	return;
}

const AController* Controller = PawnOwner->GetController();
if (Controller && Controller->IsLocalController())
{
	// apply input for local players but also for AI that's not following a navigation path at the moment
	if (Controller->IsLocalPlayerController() == true || Controller->IsFollowingAPath() == false || bUseAccelerationForPaths)
	{
		ApplyControlInputToVelocity(DeltaTime);
	}
	// if it's not player controller, but we do have a controller, then it's AI
	// (that's not following a path) and we need to limit the speed
	else if (IsExceedingMaxSpeed(MaxSpeed) == true)
	{
		Velocity = Velocity.GetUnsafeNormal() * MaxSpeed;
	}

	LimitWorldBounds();
	bPositionCorrected = false;

	// Move actor
	FVector Delta = Velocity * DeltaTime;

	if (!Delta.IsNearlyZero(1e-6f))
	{
		const FVector OldLocation = UpdatedComponent->GetComponentLocation();
		const FQuat Rotation = UpdatedComponent->GetComponentQuat();

		FHitResult Hit(1.f);
		SafeMoveUpdatedComponent(Delta, Rotation, true, Hit);

		if (Hit.IsValidBlockingHit())
		{
			HandleImpact(Hit, DeltaTime, Delta);
			// Try to slide the remaining distance along the surface.
			SlideAlongSurface(Delta, 1.f-Hit.Time, Hit.Normal, Hit, true);
		}

		// Update velocity
		// We don't want position changes to vastly reverse our direction (which can happen due to penetration fixups etc)
		if (!bPositionCorrected)
		{
			const FVector NewLocation = UpdatedComponent->GetComponentLocation();
			Velocity = ((NewLocation - OldLocation) / DeltaTime);
		}
	}
	
	// Finalize
	UpdateComponentVelocity();
}

};`
可以发现这里官方也注释了为了防止突然的位置变换导致速度异常,但是为什么在Collision触发的情况下会导致 NewLocation 和OldLocation差值过大就很奇怪。
目前有一个简单蓝图解决方案:
(在下一帧开始时强制设置速度为0并再次确保位置正确)


后面有时间编译下源码debug看看代码里怎么改比较好

热门相关:我的抖音太无敌   美漫大幻想   重生嫡女谋天下   国民女神:重生王牌千金   闪婚总裁很惧内