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).
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?
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.
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.
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.
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.
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:
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:
But please do tell if I’m completely missing the point.
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.
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.
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.
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…