UE HandleBlockingHit

在做子弹穿透功能时对部分源码的一点分析。

在UProjectileMovementComponent::TickComponent()中,当遇到阻挡时候,也就是Hit.bBlockingHit = true的情形,会调用UProjectileMovementComponent::HandleBlockingHit()方法,然后根据其返回值EHandleBlockingHitResult进行相依的处理

		if( !Hit.bBlockingHit )
		{
			//处理没有阻挡的逻辑
		}
		else
		{
			.......................

			// Handle blocking hit
            
            .....................
			const EHandleBlockingHitResult HandleBlockingResult = HandleBlockingHit(Hit, TimeTick, MoveDelta, SubTickTimeRemaining);
			if (HandleBlockingResult == EHandleBlockingHitResult::Abort || HasStoppedSimulation())
			{
				break;
			}
			else if (HandleBlockingResult == EHandleBlockingHitResult::Deflect)
			{
				NumBounces++;
				HandleDeflection(Hit, OldVelocity, NumBounces, SubTickTimeRemaining);
				PreviousHitTime = Hit.Time;
				PreviousHitNormal = ConstrainNormalToPlane(Hit.Normal);
			}
			else if (HandleBlockingResult == EHandleBlockingHitResult::AdvanceNextSubstep)
			{
				// Reset deflection logic to ignore this hit
				PreviousHitTime = 1.f;
			}
			else
			{
				// Unhandled EHandleBlockingHitResult
				checkNoEntry();
			}
			
	        .............................
			
		}

EHandleBlockingHitResult指在HandleBlockingHit()被调用后模拟应该如何进行

// Enum indicating how simulation should proceed after HandleBlockingHit() is called.
	enum class EHandleBlockingHitResult
	{
		Deflect,				/** Assume velocity has been deflected, and trigger HandleDeflection(). This is the default return value of HandleBlockingHit(). */
		AdvanceNextSubstep,		/** Advance to the next simulation update. Typically used when additional slide/multi-bounce logic can be ignored,
								    such as when an object that blocked the projectile is destroyed and movement should continue. */
		Abort,					/** Abort all further simulation. Typically used when components have been invalidated or simulation should stop. */
	};
  1. Deflect: 假设速度已经偏转,并触发HandleDeflection()。HandleBlockingHit()的默认返回值。
  2. AdvanceNextSubstep: 提前到下一个仿真更新。通常用于附加滑动/多次弹跳逻辑可以忽略的情况,例如当阻挡弹丸的物体被摧毁而运动应该继续时。因此实现弹丸穿透可以重写HandleBlockingHit方法并返回该值。
  3. Abort: 中止所有进一步的模拟。通常在组件失效或应停止模拟时使用。

 

  • 16
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值