# Generate hit events without stopping | Bullet penetration

**URL:** <https://forums.unrealengine.com/t/generate-hit-events-without-stopping-bullet-penetration/432287>\
**Category:** Blueprint\
**Tags:** bullet, unreal-engine, Blueprint, question, CPP\
**Created:** [August 23, 2018, 1:40pm UTC](https://forums.unrealengine.com/t/generate-hit-events-without-stopping-bullet-penetration/432287 "2018-08-23T13:40:43Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Takao\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Takao\_1](https://forums.unrealengine.com/u/Takao_1)\
**Post date:** [August 23, 2018, 1:40pm UTC](https://forums.unrealengine.com/t/generate-hit-events-without-stopping-bullet-penetration/432287/1 "2018-08-23T13:40:43Z")

</div>

Is it possible to generate hit events **with a moving object** , without blocking / stopping the actor?

I wan’t to make a bullet penetration system, so that bullets can move through walls, if the bullet’s penetration is high enough.  
The problem is, that when I enable hit events and set the response to “block”, then of course the bullet will be stopped on hitting something.

Using “OnBeginOverlap” isn’t possible here, because the bullet moves so fast that the actor location isn’t at the hit location anymore (even when activating CCD).

---

<div class="post-metadata">

**Author:** ![Rukgul](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rukgul](https://forums.unrealengine.com/u/Rukgul)\
**Post date:** [August 23, 2018, 1:59pm UTC](https://forums.unrealengine.com/t/generate-hit-events-without-stopping-bullet-penetration/432287/2 "2018-08-23T13:59:06Z")

</div>

Have a watch of this video, 10 minutes. Explains the basics of line trace and generating hits.

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/0/5/c059ef303f6b11602896796cc55b215c0ce0f257.jpeg "WTF Is? Line Trace By Channel Node in Unreal Engine 4 ( UE4 )") ](https://www.youtube.com/watch?v=yo9VrxFgUJY)

---

<div class="post-metadata">

**Author:** ![Takao\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Takao\_1](https://forums.unrealengine.com/u/Takao_1)\
**Post date:** [August 23, 2018, 2:14pm UTC](https://forums.unrealengine.com/t/generate-hit-events-without-stopping-bullet-penetration/432287/3 "2018-08-23T14:14:12Z")

</div>

I think I have haven’t made my question clear:  
I am aware of line traces, however I want to generate hit events with a **moving actor**.

So I assume I need to set the projectile to NOT block other channels / objects and make a line trace each frame to see if the projectile will hit something?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 24, 2018, 11:19am UTC](https://forums.unrealengine.com/t/generate-hit-events-without-stopping-bullet-penetration/432287/4 "2018-08-24T11:19:20Z")

</div>

How fast are your bullets?

> and make a line trace each frame

This may not be enough, if you cover 1 meter in 1 frame, you might miss a headshot.

Have you considered using `Mulitsphere Trace for Objects`, it returns an array of Hit Result structs.

![251448-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/b/28bdedd4a0cf730d6222007abad3d935b1f17f29.png)

Since you know the bullet velocity and distance, you can tell the time of hit, too. Once you have the data, you can calculate the possible penetration outcome and send the bullet flying to the last unpenetrable location.

This will not work great if the target is moving fast and the bullet is slow since you’re checking for collisions _here and now_ rather than _over there and then_.

* * *

If you’re using physics for the bullets, there is an advanced projectile prediction node that does the time calculation automagically, it takes custom simulating frequency as input. Never used it for anything professional, though.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 24, 2018, 11:56am UTC](https://forums.unrealengine.com/t/generate-hit-events-without-stopping-bullet-penetration/432287/5 "2018-08-24T11:56:05Z")

</div>

Thinking about it. You could have the bullet blocked as normal. That’s fine. Calculate if it does, indeed, manage to penetrate the target. If so, relaunch it again, in the same direction, slowed down/with less energy.

---

<div class="post-metadata">

**Author:** ![Takao\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Takao\_1](https://forums.unrealengine.com/u/Takao_1)\
**Post date:** [August 24, 2018, 3:16pm UTC](https://forums.unrealengine.com/t/generate-hit-events-without-stopping-bullet-penetration/432287/6 "2018-08-24T15:16:14Z")

</div>

The bullets will be as fast as real bullets. So a 7.6 mm bullet will fly at 833 m/s.

> This may not be enough, if you cover 1 meter in 1 frame, you might miss a headshot.

How so?  
At 800 m/s and 60 fps the bullet would move 13 meter per frame.  
The thing is, when actors have collision enabled, the engine will use sweeps during their movement to determine if they collide with something. Making a raytrace is (should be) the same.

> relaunch it again, in the same direction, slowed down/with less energy.

That should work, too.  
However in this case I would need to make sure, that the bullet can spawn behind the target without colliding. Also when the target is moving away from the bullet and moves first, he might move into it and get hit again.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 24, 2018, 3:51pm UTC](https://forums.unrealengine.com/t/generate-hit-events-without-stopping-bullet-penetration/432287/7 "2018-08-24T15:51:35Z")

</div>

> How so? At 800 m/s and 60 fps the  
> bullet would move 13 meter per frame.

That’s precisely what I meant - doing a separate ray trace every frame, means doing it every 13m. On the other hand, I never made a working system like this; not going to pretend I understand all the subtleties.

How are you moving the bullet at the moment? Sweep will give you a location where the objects do not overlap.

There’s a bit of misunderstanding regarding what sweep is. Consider the following:

 ![251473-capture.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/b/d/0bd2a248747b41dd99f7c69fce85a5ba3f7ab66f.png)

You will not get a hit if you run it like this because this movement is not a Sweep. The object just moves too fast (you will get a _Nope_ if you move it slowly, though). In this very case, none of the Print Strings will work here. You will get a hit as soon as you enable Sweep. Perhaps, all you need to do is to enable sweep when you move the component and use overlapping rather than blocking collision.

More details in my post here:

> **[Sweep results for Overlap collision not populated](https://forums.unrealengine.com/questions/815970/sweep-results-for-overlap-collision-not-populated.html)**
>
> I’m having a lot of trouble getting anything from sweep results for a collision overlap. The event happens but the results are all zeroed out. Does something in particular have to be done to force the sweep to happen?

But please do tell if I’m completely missing the point.

---

<div class="post-metadata">

**Author:** ![Takao\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Takao\_1](https://forums.unrealengine.com/u/Takao_1)\
**Post date:** [August 24, 2018, 4:12pm UTC](https://forums.unrealengine.com/t/generate-hit-events-without-stopping-bullet-penetration/432287/8 "2018-08-24T16:12:12Z")

</div>

> That’s precisely what I meant - doing a separate ray trace every frame, means doing it every 13m.

What’s the problem of doing a 13 m long line trace every frame (= after every 13 meter of movement)?  
If I make a ray trace at a length equal to the distance I move this frame, then how can I miss something?

> How are you moving the bullet at the moment? Sweep will give you a location where the objects do not overlap.

I use the **ProjectileMovementComponent** with just an initial velocity and I have enabled physics so that the bullet falls.  
I _assume_, that UE4 is using sweeps to detect if an object will collide during movement, because how else do they wan’t to do it?  
A sweep is effectively a line trace with a collision object.  
In your example you will not get an overlap or hit events during movement, because if you un-check _Sweep_, you will teleport to the end location.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 24, 2018, 4:39pm UTC](https://forums.unrealengine.com/t/generate-hit-events-without-stopping-bullet-penetration/432287/9 "2018-08-24T16:39:17Z")

</div>

> What’s the problem of doing a 13 m  
> long line trace every frame (= after  
> every 13 meter of movement)? If I make  
> a ray trace at a length equal to the  
> distance I move this frame, then how  
> can I miss something?

Do a trace, there’s a wall 5m away, move another 8m, do a trace. There was something on the other side of the wall you did not trace against. In addition to doing it every frame, you’d need to do it again, after the penetration. Not a biggie, that would work.

> In your example you will not get an  
> overlap or hit events during movement,  
> because if you un-check Sweep, you  
> will teleport to the end location.

That is correct. It was just a demonstration in case things were unclear. They were quite clear, I see.

> I assume, that UE4 is using sweeps to  
> detect if an object will collide  
> during movement

I just tested it in the 1st person template. Set the projectile’s component to overlap, ensured that targets generate hit events on overlap and it returns a sweep result. So using overlap for this should be fine.

---

<div class="post-metadata">

**Author:** ![Takao\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Takao\_1](https://forums.unrealengine.com/u/Takao_1)\
**Post date:** [August 24, 2018, 4:46pm UTC](https://forums.unrealengine.com/t/generate-hit-events-without-stopping-bullet-penetration/432287/10 "2018-08-24T16:46:54Z")

</div>

> In addition to doing it every frame, you’d need to do it again, after the penetration.

Ether that or a multi line trace. Could be interesting what has a better performance.

> So using overlap for this should be fine.

Nope they are: The event _On begin overlap_ is called AFTER the projectile has moved or at least not at the moment the component hits the other object. I tried this.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 24, 2018, 5:40pm UTC](https://forums.unrealengine.com/t/generate-hit-events-without-stopping-bullet-penetration/432287/11 "2018-08-24T17:40:17Z")

</div>

Hm, I did not test it that thoroughly but it seems to work rather well on my end:

 ![251494-cap1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/2/8/028388ad793b763b8e1e682487a0a2a54e81dab5.png)

![251495-untitled.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/6/d/86df7d8f75115ee992f6920fcdd0bb42a7eda794.png)

What am I doing wrong?

---

<div class="post-metadata">

**Author:** ![Takao\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Takao\_1](https://forums.unrealengine.com/u/Takao_1)\
**Post date:** [August 24, 2018, 6:09pm UTC](https://forums.unrealengine.com/t/generate-hit-events-without-stopping-bullet-penetration/432287/12 "2018-08-24T18:09:55Z")

</div>

I hadn’t used **On COMPONENT Begin Overlap** , but **On ACTOR Begin Overlap**. That one does not have a sweep result.  
Also I used the actor location and not **Location** from **Sweep Result**.

edit: What is interesting is, that when I activate pyhsics, the projectile will not generate overlap events…
