Need Help projectile system

Hey reader

Ive been trying for weeks now to get some basics or at least what i thought were basics down but im having so much trouble its becoming tedious.

I am trying to create a projectile based bullet system and what i mean by that is that i want only the hit of the physical projectile to be the damage causer, i dont want to do the “projectile for show” but hit by line trace method.

I can cut to the chase straight away and ask if someone could point me to a good example of this kind of projectile so that i might better understand how it is done. Every video i have seen so far always starts with the words “Simple example” or just does not fit the description of what I am after.

Thank you very much!

For anyone interested in what i have tried so far, here is a little outline of my fail:

If you look at this image:

(NOTE: after i took the 2 shots i moved up on the target)

You will see a couple of trace lines;
The red trace lines are the trace from the Muzzle to the Camera forward * 10000
The projectile is then launched by impulse by the same Camera forward * 10000

The yellow / orange line is the projectiles trace

Sometimes it hits, sometimes nothing as you see in the image there should have been 2 but there is only one and i have no idea why.

I really need a tutorial that is projectile focused and better still deals with first and third perspective (as the projectile hitting near where the cross hair is pointing is another world of ■■■■!)

I hope i explained myself well and that someone can point me in the right direction (pun intended)


Hi, couple of things:

(1) If you have small projectiles moving at high speed, you should enable CCD (Continuous Collision Detection) in your collision else your bullets might go through objects (but of course this will increase your CPU usage). Else in your projectile movement you can try checking “Force Sub Stepping” and or decrease the “Max Simulation Time Step” and or increase the “Max Simulation Iterations”. But all this will come with an increased CPU cost.

(2) As for firing to the cross hair, with bullets that’s not easy and you will have to make compromises

(3) So aiming with line trace is fairly basic, aiming good with bullets, not really :slight_smile: [HR]/HR Couple of ways you could do your aiming logic with bullets (I’m sure there are many more possible ways, but those I actually implemented once, but only use the first now):

  • Make a linetrace from your camera position to the cross hair -> return impact location
    -> use that location and aim your bullet so that it will hit that location

Pro: You will hit exactly the position of the cross hair
Con: Your aim will shift very strong/jump when aiming at close up targets vs far away targets. That’s especially problematic when you want to hit moving targets.

  • Use the weapon muzzle rotation or your camera rotation to fire the bullet
    For the cross hair position here: do a linetrace on tick/timer from the weapon muzzle with the chosen rotation, weapon muzzle or camera (same how you would shoot your bullet) and see where it hits -> return impact location -> convert that location to screen -> set cross hair position to that screen position

Pro: Your aim goes always straight from the weapon/camera, so your aim direction won’t jump
Con: The cross hair will shift very strong/jump when you shift aim between close up targets and targets far away [HR][/HR]
Seems to me you’re trying to use the second approach and use the camera rotation to aim, but not change the cross hair position based on where you aim, therefore your cross hair is not positioned where your bullet will impact. [HR][/HR]
System I use:

Linetrace for weapons like pistol, rifle, shotgun,… so very fast moving projectiles → goes exactly to the cross position so you don’t have the problems mentioned above

Bullets for slower moving projectiles, so rockets, grenades, tank cannon,… using the first aim option I described above, but I once tried both of them.


Another thing I wanted to mention, is when you use the first of the two systems mentioned above you might wanna think about making your weapon quite unprecise, so large spread, so that you don’t feel the jump in aim between close up and far away.
Then when the player goes into ironsights (weapon rotation and camera rotation are aligned in one direction, therefore you have no difference in aim between close up and far away) you make the weapon precise, so less or no spread.
I didn’t implement this though, so can’t tell you how that will work out in the game.

Try these.…yp-/index.html

Keep in mind that your frame rate may affect hit results or even projectile collision.
Aside from the substepping mentioned above.

Generally you will want to run a real trace after the projectile reports a hit to confirm if the hit was real or not.

Thank you guys for this information. I will sit down tonight and get my head around what you have shown me. @**chrudimer one thing i do not really get is how to factor in things like bullet drop when using line trace system? **

@**MostHost LA **Keep in mind that your frame rate may affect hit results or even projectile collision. This is interesting i did not know this…

If you mean line trace system as in instant damage, then you would only use this for very fast projectiles so there I wouldn’t expect any visible drop / you want to fire to the cross hair anyway.

If you meant it in the means of prediction and where to put the cross hair, how to aim the weapon with bullet drop to hit a specific location (cross hair), the two links from MostHost LA above :slight_smile:
But for fast projectiles I would disable gravity, so no drop and for others I wouldn’t use projection, so with an grenade launcher the player would need to aim higher (I would find it sort of strange when you would have an grenade launcher, aim to a spot with the cross hair and the grenade flies a curve to hit the cross hair point, but it depends on your game setup how you want to do this).

Basically if you run a physics simulation, you would run it step by step, so with an discrete delta time between those steps (for perfect analytical precision this delta time would go towards 0, that’s what calculus is. Computers can’t do this for obvious reasons).

As far as I see this in ue4 (I **don’t know **how this above has been implemented in ue4 exactly, I can only guess), is that this delta time is by default the frame time and if you would enable substepping then you would have two parameters: “Max Simulation Time Step” and “Max Simulation Iterations” to set this delta time, MostHost LA correct me if I’m wrong.

I don’t think you are wrong.
The tick event basically happens every frame.
with regular collision if something is traveling fast enough to pass through an object entirely within a single frame, the result of its collision would never be reported. Both overlapped or hit won’t matter.

this is also partially why running a line trace in tandem helps sort out if the hit occurred or not. You have some cheap redundancy to ensure the result is accurate.

As far as what you are suggesting for direct hits. Keep in mind that bullets never fly straight. They aren’t laser beams.
If accuracy in your game doesn’t matter, then yes, line traces that work like lasers are best.

if accuracy does matter, you can google the bullet trajectory algorhytm and implement a custom projectile path trace system.
the custom implementations usually end up working better then the projectile component performance wise.

As far as ease of use. The projectile component with a bigger then needed collision capsule to cheat the collision detection is a faster alternative.

Imagine a .45 bullet. If you have the collision for it about 5cm in radius 10cm in diameter, the hit/overlap events can happen even when the bullet is traveling below 10 cm per frame.

I would use this collision/overlap event to run a reverse trace and see if the character is hit instantly. 1 calculation, result avaliable in the next frame. Using the army ballistics calculus.

That’s the proof positive the hit has indeed occurred, and it’s fairly cheap performance wise without need for substepping even.

keep in mind your projectile speed has to dictate the radius of your collision.

I never expected such informative replies, thank you for that. For clarity, i am wanting to create an arma 3 / dayz character setup so far as the shooting mechanic and camera control. Still not having great success between first and third switch and cross hair alignment (trying not to have to move the cross hair). I certainly have a great deal to learn.

I watched this video and its really nice although i have never played the game. I think its great that Unreal do this, give people like me who want to learn (but for reasons cannot get formal training) an insight into what goes into projectile systems.

I have taken the video at the correct time but should that not work you can skip to the 36 min mark.

Im sure you guys have enough to be doing but if either (or both) wish to mentor anyone now and again i would truly appreciate that! I have subscribed to you both.

I would also like to add, I’m not trying to build a game here per say, more learn by doing. Never been fantastic at reading cover to cover… i like to jump to the good stuff :wink:

I scrapped everything and started again, i’m thinking now (for 3rd person) however of spawning the projectile somewhere front of the weapon between the muzzle and the camera or have I totally lost the track here?

Keep the spawn where it should be. At the muzzle via a socket usually.

Sandstorm wasn’t too great in terms of UE4 usage.
a good one would be the outer worlds. Though the weapons in it feel more like line traces without a bullet drop.

Back to the socket thing.
It doesn’t matter where it is spawned. What matters is that you pass along the look at rotation between the muzzle and the end point on the cursor.
the end point at the cursor can be found via a single line trace, which is also your “instant” hit detection.

The next portion should take that trace info into account and allow for the spawn of the projectile aimed at the correct target.

The projectile at that point can do its thing.

If you want to implement it like sandstorm, you can use the first raytrace as a hit if the hit distance is below 50m or so. And use the simulate only afterwards.

Obviously this is different then first person. But to get the angle of the shot from the muzzle to the target you still need the information on the target, so it’s the only way i can think it.