How do i prevent a Projectile Movement Component to stop when it hits something?

Hello!

I lurked around in the documentation of UProjectileMovementComponent and I think I found more effective way to make the bullet unstoppable.


SOLUTION

  1. Create UProjectileMovementComponent inheriting movement component class

  2. Add lines to your created component class to override next functions:

    EHandleBlockingHitResult HandleBlockingHit(const FHitResult& Hit, float TimeTick, const FVector& MoveDelta, float& SubTickTimeRemaining) override;
    void HandleImpact(const FHitResult& Hit, float TimeSlice = 0.f, const FVector& MoveDelta = FVector::ZeroVector) override;
    
  3. Implement HandleBlockingHit function as seen below:

    Super::HandleBlockingHit(Hit, TimeTick, MoveDelta, SubTickTimeRemaining);
    return EHandleBlockingHitResult::AdvanceNextSubstep;
    
  4. Leave HandleImpact function empty




EXPLANATION


Projectile movement component is running TickComponent method to update the motion of the updated component. Each time our updated component hits something, HandleBlockingHit function is executed, which will then return EHandleBlockingHitResult enum type value to decide what to do next with the updated component. The enum value comes basically from HandleImpact function, which by default checks whether the bullet is bouncing or not.

  1. if bullet is not bouncing StopSimulating function will be executed and the updated component will be set to null, HandleBlockingHit will return EHandleBlockingHitResult::Abort value
  2. If bullet is bouncing, HandleBlockingHit will return EHandleBlockingHitResult::Deflect value and will start counting bounces
  3. there is also a third enum value EHandleBlockingHitResult::AdvanceNextSubstep in this enum, specially designed for that case scenario (I assume) as based on the value, hit events are ignored in TIckComponent function.

So when the bullet is meant to move after hit events you would want to return EHandleBlockingHitResult::AdvanceNextSubstep in HandleBlockingHit function. A remark why to leave HandleImpact function empty - you wouldn’t need to use any logic there because the bullet is not bouncing and otherwise it will stop simulating component velocity.



If you have any further questions or you didn’t understand some part of it, feel free to ask.

With regards!

2 Likes