No announcement yet.

ProjectileMovement Vs Raycasts for Bullet Drop, Penetration, Ricochet

  • Filter
  • Time
  • Show
Clear All
new posts

    ProjectileMovement Vs Raycasts for Bullet Drop, Penetration, Ricochet

    I have been thinking about making a shooting range in UE4 some what realistic at least in terms of Ricochet, Bullet Drop and Penetration.

    My first bet is to use Raycast for this As Realistic Bullets are Fast so using Projectile Object might not be the best idea as that might miss collisions or glitch due to frame rates (Correct me if i am Wrong).

    Using Raycast:​​​​​​

    1)As for using Raycast the Idea is to have Smaller Raycasts and if the Hit Result is NULL we can Create another Raycast from the Ending Location of previous one and set its Ending point a bet below to simulate the bullet drop effect. Again I haven't really dived into the Curves of UE4 so if there exists a better solution please do share.

    2)Now for the Penetration using MultiRaycast might be more than enough for this depending on the Physical Material we can add the impacts more Hits Rather than only the first one.

    3)Ricochet or Bounce that might be a bit difficult and I kind of don't really know what to do here. One Option is to Create Another Raycast From the Impact Point to a Random Endpoint but again there is the problem of Right Rotation. Some kind of Reflect Vector.

    I would be posting the Solutions or any progress Here as I Go along any help is great you can share your wisdom.

    Why Not Projectiles:

    So, for Performance Reasons I decided not to use Projectiles I think they are an over kill for Automatic Weapons like Assault Rifles and Machine Guns better to have Hundreds of Raycasts than a fully simulated physics object bouncing around your scene.

    Now I may be a bit harsh on Projectile Component but honestly I don't know much about it, you can help me decide.

    OK, you are wrong. Bullets don't *EVER* travel in straight lines. Laser guns might though, if they existed. Lasers definitely do travel a straight line, and at the time of light.

    1) use math instead? it's probably faster to boot. You have a start point, you have gravity. you can estimate the speed. the rest is math.

    2) what? why would you add more hits? that's confusing. do you mean continuing on after the first hit? sort of the same as 3.

    3) that's already an option with ray tracing, basically you can detect the Normal of the item you hit, and decide via math at what angle the bullet should ricochet. there's precise formulas for this depending obviously on velocity, spin, composition of the bullet (FMJ, vs led) hardness of the material, etc.

    Don't even mention "Somewhat realistic" if you aren't using projectiles of some sort (you could make your own component with your own mathematical formulas). And USUALLY, projectiles don't impact performance for their lifespan is too short to do so. (normally you remove them after impact or shortly after in the case of a ricochet Any decent tutorial will show you how to get them to destroy, any tutorial that doesn't should be automatically not watched).
    In other words, unless you have 100 players all contemporaneously shooting into a badly made MMO you have no chance of getting hundreds of projectiles lingering around long enough to cause performance issues, even with way more intense calculations happening then the projectile component calls for, and crazy Cascade/Niagara particle effects within the projectile....


      Originally posted by MostHost LA View Post
      I wasn't talking about a single Raycast and i managed to do it and it works perfectly.
      here is the result.

      Now the Question is, is it worth the effort or I should simply use Projectile Movement Component ?
      Last edited by HarisNauman; 12-07-2019, 03:30 PM.


        It's pre-done with all the math you need... I think it even takes bullet weight into account for the flight.

        If you want to go through the math, it's definitely good exercise. The most likely place to find accurate math is army related stuff.



          Was a good Exercise learnt a lot of new things. All this is based upon simple raycasts everything is calculated and kept up to date all the way from Bullet Spawning to its Stopping.


            Are you taking into account some physmat parameters?
            if you wanted to go the extra step that's where you should look into.

            maybe even create some accurate physical materials parameters for bullet penetration.

            physmat is the hard way. The easy way would be to make a couple of tags and assign them for changing penetration values/stopping power.


              Yeah i am going for the PhysMaterials and their Density.


                Originally posted by MostHost LA View Post

                You are wrong. Light usually does not travel in straight line because it is affected by :
                - gravity
                - the thing it goes through, like water

                Also, the speed of light can get lowered when passing through some stuff like water or glass.
                Physics > Graphics


                  Fair point.

                  however for all intensive purposes laser beams at such a short range such as that of an hypothetical laser gun would not travel far enough to receive much of any drift from gravity.

                  If you read it, this study states that the maximum drift specific to high pulse beams is at most the diameter of the beam. (Sort of random, without a distance for reference or knowing what happens if you add more diatance past that point).

                  as for your second statement, yes. Or we wouldnt have values for Refracrion.
                  However... how would you possibly be able to simulate this in Unreal anyway? Meaning, if you shot a waterfall with a laser gun, how would you possibly tell the engine to delay an accurate amount when the original measure is already well outside of the engine capabilities? It ends up making no sense at all.
                  The immidiate result if the raycast is probably lready way later then the speed of light would be.
                  And even if it somehow were not, and you managed to add a delay of .000000000000000000000.... probably going to go on for several pages of 0 until a 1 - what purpose would that ever serve?


                    The impact of these physical phenomenons depends of the type of game you are making.

                    Yes, you can ignore them when shooting a laser on a 1 km distance.
                    However they are important to properly render a black hole in Elite Dangerous for example :

                    Last edited by Rainoxer; 06-03-2020, 07:18 AM.
                    Physics > Graphics


                      you could use both methods at the same time. For projectiles I usually use the projectile movement component to handle the movement, that comes with the options for bouncing and substepping and all the in built goodness.

                      i have no collision on the projectile itself and use traces instead. On every tick trace from the location from the previous tick to the current location. I usually set up a couple of sockets on the projectile aswell, one at each end to use in the trace.

                      Not sure how well that would work with bullet drop though to be fair.