UE HandleBlockingHit

文章详细分析了游戏开发中的UProjectileMovementComponent在处理子弹穿透时,HandleBlockingHit方法的执行过程,特别是EHandleBlockingHitResult枚举在不同情况下的作用。着重讲解了Deflect、AdvanceNextSubstep和Abort几种结果的含义及应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

在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: 中止所有进一步的模拟。通常在组件失效或应停止模拟时使用。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值