x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Generate hit events without stopping | Bullet penetration

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).

Product Version: UE 4.20
Tags:
more ▼

asked Aug 23 '18 at 01:40 PM in Using UE4

avatar image

Takao_
206 6 6 15

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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

https://youtu.be/yo9VrxFgUJY

more ▼

answered Aug 23 '18 at 01:59 PM

avatar image

Rukgul
38 2 8

avatar image Takao_ Aug 23 '18 at 02:14 PM

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?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

alt text

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.

capture.png (219.9 kB)
more ▼

answered Aug 24 '18 at 11:19 AM

avatar image

Everynone
15.3k 77 26 64

avatar image Everynone Aug 24 '18 at 11:56 AM

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.

avatar image Takao_ Aug 24 '18 at 03:16 PM

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.

avatar image Everynone Aug 24 '18 at 03:51 PM

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:

alt text

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:

https://answers.unrealengine.com/questions/815970/sweep-results-for-overlap-collision-not-populated.html

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

capture.png (125.8 kB)
avatar image Takao_ Aug 24 '18 at 04:12 PM

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.

avatar image Everynone Aug 24 '18 at 04:39 PM

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.

avatar image Takao_ Aug 24 '18 at 04:46 PM

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.

avatar image Everynone Aug 24 '18 at 05:40 PM

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

alt text

alt text

What am I doing wrong?

cap1.png (102.3 kB)
untitled.png (125.6 kB)
avatar image Takao_ Aug 24 '18 at 06:09 PM

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...

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question