UE floating pawn movement Bug Set location 导致速度异常发射
  fBPubYo5OeJb 12天前 24 0

最近做传送门的时候发现一个很好玩的问题,当我通过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看看代码里怎么改比较好

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 12天前 0

暂无评论

推荐阅读
fBPubYo5OeJb