Download

best solution for bullet drop and flight time?

i see people use line traces all the time, and for most games where gunfights take place at such close range, bullet drop is negligible in real life that its not worth coding into a game, but long range shots getting out past a couple hundred meters, drop becomes noticeable… i do not know if you can arc a line trace, i havent seen to many people doing that either, but it seems like spawning a projectile is the preferred method of this, but it comes with problems having to render such a fast moving object that nobody will see anyway

why dont i see anybody using the predict projectile path by channel node?.. it can predict the flight path without rendering the object, give bullet drop… if you could apply some kind of a flight time to this, wouldnt it work better than a line trace or spawning of a physical projectile?

im trying to figure out what route i will go, i am actually leaning more towards a typical line trace and no bullet drop as im not really anticipating a lot of long range gunplay, and since it’ll be one of a sci-fi setting and may involve an energy weapon which would have no drop anyway, that may be the best solution if i cannot come up with a simple, robust way to get accurate bullet drop and time of flight that isnt going to be a large drag on the server, but it seems to me spawning a physical projectile is going to cause a lot of issues in online play

most accurate solution: Projectile motion - Wikipedia

what im thinking about the predict projectile path node is for something traveling at the speed of a bullet, its going to need an insane amount of checks per second in order to reliably detect a hit… you would still have to figure something out for flight time… would this be more or less of a performance hit than spawning a projectile at velocity, then writing a script for that projectile to decrease velocity a certain amount every cycle of a timer (simulating the loss of velocity due to drag)… and could you still use the projectile, but not actually render it to save on performance… what would the hit be on that vs the predict projectile path?.. and how reliable are overlapping events at that velocity?

I used projectile component few times, and overlap works fine up to 18-20k velocity. More than than and some bullets go trough door.

do you render the projectile when you do it? is there a way to save resources with it being invisible and unrendered?

im going to test some things

i did some testing with physical projectiles… using the event begin play node to apply a linear velocity to the projectile, in the settings of the projectile blueprint i could apply a damping to linear velocity that slows it over time to give it realistic deceleration on top of bullet drop and time of flight… however, about 25% of the impacts would miss the wall with a velocity set to 5000 which is much slower than one would expect a bullet to travel at… constant collision detection needs to be ticked on to solve this issue but i do not know how much of a hit to performance this would be in a game with multiple players and fully automatic weapons

and doing some more reading on CCD ive learned that it is in fact a major resource hog

whelp… physical projectile isnt going to do it, too unreliable ,too much resources to do CCD, so instead i went with a line trace

for a line trace, i have an empty actor spawn at the muzzle of the rifle… on the eventbeginplay node, it sets the current actor location, then runs an event by timer which loops a line trace by channel which takes actor location (beginning with the muzzle) and multiplies that by a float, which is use for the velocity of the projectile, then adds that to the actor location for an end point… if the line trace fails to hit anything the end location of the trace sets a new actor location as the event cycles again drawing a trace from the previous end location… on every cycle a certain amount of velocity is subtracted from the starting velocity, so the trace slows down over time, and a constant Z velocity is applied to the line trace end vector to apply drop… so i have a line trace with time of flight and bullet drop and i can easily divide remaining velocity with starting velocity and multiply that by maximum damage to get a variable amount of damage cast based on projectile velocity

aah… and now the results of all my testing

projectile turrets, 48x of them firing on a timer loop of about 600 rounds per minute took me down from 120 frames to about 95… turning off the meshes added a single frame per second

line traces with bullet time and bullet drop, 48x turrets also at 600 RPM dropped me down to 117 frames per second from 120, a massive improvement over projectiles

standard line traces without bullet time or drop showed no noticeable drop in frames, not even when i doubled the turrets to 96 and even multiplied the fire rate to 6,000RPM

so my conclusion? i will not be using physical projectiles for anything other than grenades, or low velocity projectiles, like those from grenade launchers… the arcing line traces i made up should easily be adequate for any long range FPS game with any reasonable amount of players… should is the key word… performance could be saved by using standard line traces when not viewing through a scope… and for short range weapons, nothing beats the standard, simple line trace

ah hah… i managed to decrease the time it takes to draw each trace down to 0.05 seconds, which makes the trace even more accurate, and managed to get it to do so while only losing maybe half a frame per second vs the standard straight line traces by putting in a counter, this counter determines how many loops have passed, and if it reaches its limit without making a hit, it’ll destroy the actor… so the line traces are self destructing after a certain distance now for cleaup which saves a lot of resources meaning my traces have time of flight and bullet drop with no noticeable drop in performance with 48 turrets going at once… i have my ballistics system now… it just needs a bit more polishing and we’re good… i’ve come to the conclusion that this by far is the best way to get bullet drop and flight time in a bullet and be super light on resources