Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Physical Bullet System

Discussion in 'Scripting' started by Greenboykin, Feb 1, 2020.

  1. Greenboykin

    Greenboykin

    Joined:
    May 22, 2019
    Posts:
    9
    I am experimenting with a realistic shooter. I read that physical bullets are the way to go for bullet drop and realistic physics but I can't find any recent information for unity on the topic.
     
  2. diXime

    diXime

    Joined:
    Oct 2, 2018
    Posts:
    162
    Hello,
    there are many ways of doing it. It really depends on the number of bullets you're using; to the tens a GameObject with a RigidBody and a Collider should be fine. In the thousands, you'll need to get a little more techy and use the DOTS stack. ECS is particularly suited for a huge number of small trivial objects moving around.
     
  3. Greenboykin

    Greenboykin

    Joined:
    May 22, 2019
    Posts:
    9
    thank you. I am currently just trying to set up a realistic system for shooting and such and will probably expand it later. Is there a method that is better suited to expanding than another?
     
  4. diXime

    diXime

    Joined:
    Oct 2, 2018
    Posts:
    162
    The modular workflow of Unity makes it quite easy to expand when you want to, whatever approach you go for. What you need to use really depends on the optimisation level you're aiming for, and this :
    To do something realistic, you'll need a physics engine that looks as such. Unity Physics is extremely good and performs really well (I think I've read somewhere it's even ecs-based). ECS doesn't provide one by default, so unless you want to take the challenge of hard-coding something likely to be less optimal than Unity build-in engine, which is not a bad option at all (learning is great! and you'll only get the options you need, when you need them), RigidBody may be the course of action you'd rather start with.

    Then again, if you want 10 000 agents shooting a hundred bullets, GameObjects won't do the trick. It really depends on the type of game.
    I'll give you an example, and a counter example.
    Example 1 : a RTS with realistic bullets. ECS may be better. a FPS with one player shooting NPC will work perfectly with GameObjects.
    Counter-Example : Overwatch (12 players in teams of 6, so small numbers) is using an entities workflow. Sometimes, when you go for hardcore optimisation, there's no way around the DOTS stack. Now if you're alone, you may not want to spend months working on your physics engine.
     
    Last edited: Feb 2, 2020
  5. Greenboykin

    Greenboykin

    Joined:
    May 22, 2019
    Posts:
    9
    I am really bad at coding, and have very little experience with the intricacies of the unity engine, where do I need to start because I don't know how to apply the unity physics engine or how to even spawn the bullets when I shoot.
     
  6. Greenboykin

    Greenboykin

    Joined:
    May 22, 2019
    Posts:
    9
    I am interested in learning, I still haven't made a player controller but there is plenty of material to learn that and unity comes with one, so I would love to be able to craft my own script for both movement and shooting but I figured I should gather information before I start something.
     
  7. diXime

    diXime

    Joined:
    Oct 2, 2018
    Posts:
    162
    Don't worry, everyone is, and even I, who code since I was a child, still learn almost everyday and gets confused by the most trivial problems. Coding is making mistakes again and again without loosing your enthusiasm. At least, my way of doing it.

    So:
    Physics Engine will be used anytime you use these components:
    https://docs.unity3d.com/Manual/PhysicsSection.html
    To spawn GameObjects by code (for example on clicking), there is Invoke, InvokeRepeating (great for machine guns with a specific spawn rate), Instantiate... They quite depend on the situation.

    If you're looking for good youtube guides on programming, Coding Train (Processing, Java) is great to understand some hard topics and seeing someone making mistakes and having fun doing them.
    Brackeys, Coding Monkey and Sebastian Lague are doing quite good guides specific to Unity, and many others. Be careful when copying code from videos, their version of Unity may be different and we get a lot of questions here about people copying code without understanding them well, doing mistakes in the process.

    Actually, I'd be even more precise: It's great to draw a chart, a little schema, of what you're trying to achieve before starting. It really helps, and when I get into troubles, the solution is often that I need to clear my mind of the various challenges before starting coding.
     
  8. Greenboykin

    Greenboykin

    Joined:
    May 22, 2019
    Posts:
    9
    I guess what I am trying to achieve is a nice movement system (crouching, prone, and maybe climbing), A weapon system (preferably modular so I can slap the code onto a gun and specify if it is single fire burst full auto or all, the bullet speed/bullet type ect.) and a inventory system similar to Tarkov's to start and build off of there
     
  9. Greenboykin

    Greenboykin

    Joined:
    May 22, 2019
    Posts:
    9
    I kinda wanna make a base similar to arma and build off of that
     
  10. Inxentas

    Inxentas

    Joined:
    Jan 15, 2020
    Posts:
    275
    I'm not trying to demotivate you, but I've got this feeling you'd be better off trying to code something simpler then going for absolute realism. Start with the basics of the Physics engine without worrying too much whether or not your game looks realistic.

    It will be more fun and less frustrating as well.
     
    diXime likes this.