Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Realistic ballistic physics

Discussion in 'General Discussion' started by MadJohny, Jul 29, 2014.

  1. MadJohny

    MadJohny

    Joined:
    Mar 8, 2013
    Posts:
    143


    Hi, I've been wondering how actual bullets travel in space, same for arrows (for crossbows or recurve bows), is this video a realistic representation, or is it not? Any videos/articles you recommend me watching to get more knowledge on this? I find the physics on the link a bit weird the that they just kinda suddently drop down.

    Edit: How much do bullet physics differ from arrow physics? (shot from a recurve bow for exemple).

    Edit2: Apparently the youtube was totally getting in the way of the whole post
     
    Last edited: Jul 29, 2014
  2. calmcarrots

    calmcarrots

    Joined:
    Mar 7, 2014
    Posts:
    654
    I think it would be easier if you just ditch this and start an MMORPG
     
    Joe-Censored likes this.
  3. MadJohny

    MadJohny

    Joined:
    Mar 8, 2013
    Posts:
    143
    Don't make me go back to the meme page.
     
  4. Kinos141

    Kinos141

    Joined:
    Jun 22, 2011
    Posts:
    969
    One way is to instantiate a physics object and AddForce really far and fast.
     
  5. MadJohny

    MadJohny

    Joined:
    Mar 8, 2013
    Posts:
    143
    I'm not asking (yet) how to replicate it in unity, just want to have some more insight into it, also, when I start making it, I feel like I won't use rigidbodies at all...
     
  6. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    realistic and not using rigidbodies makes zero sense.

    I would say implement using physics/rigidbodies, then try simulate the same flight paths using nonphysics if you so choose, because currently the trajectories dont look anything near realistic
     
  7. Lostlogic

    Lostlogic

    Joined:
    Sep 6, 2009
    Posts:
    693
  8. MadJohny

    MadJohny

    Joined:
    Mar 8, 2013
    Posts:
    143
    The thing is performance, I wonder how much impact bullet rigidbodies would have.

    Edit: well, for a bow and arrow weapon it might not be that bad since the fire rate is low, but if we're talking about automatic guns I think that it would impact a lot, ofc there is object pooling, but still...

    Edit2: Some of the trajectories seen on the first video I sent actually looks like the ones seen here: (1:18m)

     
    Last edited: Jul 30, 2014
  9. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    Very little impact since most of them probably will be traveling too fast to actually have their collisions detected. Bullets don't typically need to be represented as anything other than a point traveling through space i.e. a ray.

    The first video isn't bad as far as ballistic trajectory physics is concerned, and probably is more accurate than 80% of the FPS games out there. The Arma video is more about material penetration. I'm sure if you look you can find tons of examples of it done in unity. It's not hard to do, it's just a pain in the ass to set up and to keep it from eating performance.

    Also, the only difference between bullets and arrows is in the variables, otherwise it is the exact same physics.
     
    MadJohny likes this.
  10. Tiny-Man

    Tiny-Man

    Joined:
    Mar 22, 2014
    Posts:
    482
    I just code all my physics in a script, which moves an empty gameobject. Then linecast my old pos to current for impact, in case my bullet went through an object.
     
  11. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    864
    Using a rigidbody-based bullet you will initially run into the problem that it skips through thin colliders in-between physics steps, so use a script like this one from the wiki helps by raycasting the space that the collider 'skipped through' each physics step, to check whether you should have hit anything.
     
    MadJohny likes this.
  12. Kinos141

    Kinos141

    Joined:
    Jun 22, 2011
    Posts:
    969
    not much if you object pool. Instantiating and destroying can take up memory if the object spawned has many procedures on its start method. If using on mobile, then forget it: pooling is the way to go.

    Other than that, if you want to code it by hand, then you have to learn trajectories in physics. If you're not strong in physics, then get strong in physics!! lol
     
  13. MadJohny

    MadJohny

    Joined:
    Mar 8, 2013
    Posts:
    143
    I'm mostly asking how to "get strong in physisc", I can't find anything that shows how real bullets travel, the only things that I can find about that are mostly game dev related. I guess I'll have to search deeper
     
  14. steego

    steego

    Joined:
    Jul 15, 2010
    Posts:
    969
    It's called External Ballistics
     
  15. MadJohny

    MadJohny

    Joined:
    Mar 8, 2013
    Posts:
    143
  16. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
  17. smd863

    smd863

    Joined:
    Jan 26, 2014
    Posts:
    292
    Here's a list of ballistics for common cartridges:
    http://www.geekation.com/ballistics-charts-for-many-rifles/

    Bullets have a measurements known as a "ballistics coefficient" that is probably sufficient for you to model the trajectories of different types of cartridges. It's a combinations of drag, mass, diameter, shape, etc. that measures a bullets ability to overcome air resistance.

    You need the mass of the bullets and its muzzle energy (i.e. how much gunpowder is packed into the cartridge) to calculate its initial velocity, and then you can use the ballistics coefficient to simulate the flight path.
     
    MadJohny likes this.
  18. mhernandez88

    mhernandez88

    Joined:
    Jul 20, 2016
    Posts:
    38
    I know this thread is old but this answer is completely wrong with respect to bullets and arrows. Bullets do not behave the same way arrows do with respect to a few variables, they are completely different.
    1. The two are blatantly different designs. Arrows are designed for very low subsonic speeds.
    Arrows typically travel at Mach .1 - Mach .3 or 1/10 - 3/10 the speed of sound
    2. Bullets mostly travel at supersonic speeds Above Mach 1 or at about ~1200feet/second. 1600 meters per second is not unusual
    3. At subsonic speeds you are not worried about the same forces as you are at supersonic speeds. Comparing Arrows to Bullets is a non starter.

    Ballistic Physics behavior differs dramatically when you cross the sound barrier, and even more dramatically when you cross back under the sound barrier from supersonic.

    If you want to learn about ballistics dont do it from a game programming reference, look up marksman videos, watch competitions, learn about all the complexities that go into understanding ballistics.


    Quick note to the person whom answered this question wrong. I know you were just trying to help, but blind leading the blind is no way to help people. A quick google search could have saved you from writing the wrong answer.
     
  19. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    As far as bullets traveling at supersonic, a few additional points as far as going for true realism.

    Rifle bullets typically exit the gun barrel supersonic, but most handgun rounds are subsonic.

    All bullets slow down in the air due to air friction (drag), and this will cause rifle rounds to pass between supersonic and subsonic at appropriately long distances. For a marksman this is a big issue, since that transition can destabilize the bullet in flight and will slightly affect its trajectory. I'm unaware of any game ever incorporating this phenomena.

    As far as using a ray cast for a bullet, that is usually fine in close quarters games, but in reality a bullet fired level to the ground falls to the ground in the same amount of time as if you dropped a bullet next to you. Simple law of gravity stuff. So a bullet's flight path is always a curve, never a straight line.

    Another detail as far a realistic bullet physics is how much damage a bullet deals to its target. In games bullets generally deal the same amount of damage no matter the distance, but in reality the amount of damage a bullet does is a combination of the design of the bullet, and the amount of energy transferred to the target. The amount of energy is of course calculated based on the weight of the bullet and the speed of the bullet on impact. So in reality a bullet fired from an M16 at around 3400 feet per second should be far more devastating at close range than when it drops to around 1100 feet per second at somewhere around 400 meters. It would be really interesting if future games would include this. It wouldn't even be that difficult to do in Unity with easy access to velocity.
     
    Last edited: Jun 6, 2018
  20. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    First off, if you aren't going to mention how arrows become massive oscillating springs in flight with a center of mass constantly warping until it stabilizes, then you've missed the single biggest difference the two have. Arrows are a giant coiled mess of energy that plays havoc with the basic quadratic formula that ballistic physics starts with, because the formula assumes a static center of mass.

    Second, all you've done is mention that subsonic and supersonic flight is different, which is true... for planes. As far as bullets are concerned, the only significant difference is the drag coefficient. You can end up with the bullet destabilizing if it drops below mach, but chances are the bullet will be off the map by then (assuming the player even has a good enough optic to see it).
     
  21. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Depends on the size of the map. The AK-47 is one of the most common video game guns there is, and a typical 7.62x39 round from one transitions to subsonic at around 450 meters. I suppose you could have a map smaller than 450 meters though.
     
  22. RockoDyne

    RockoDyne

    Joined:
    Apr 10, 2014
    Posts:
    2,234
    But how much magnification do you need before you can even see a target at that range? Then how important is it that you lose accuracy at a range that you aren't really meant to shoot accurately at anyway?
     
  23. AndersMalmgren

    AndersMalmgren

    Joined:
    Aug 31, 2014
    Posts:
    5,358
    A 5.56 muzzle velocity is around 900-1000 m/s depending on rifle bore length and ammo used. At 90 fps, 11ms, the bullet travels 11 meters per frame. So you you raycast 11 meters per frame. Each frame you take into account gravity and ballistics coefficient. Sure it will not be a smooth arc but its good enough