I want to simulate arma 3 like bullet trajectory but I have no idea about how to do it. What should I do? raycast, rigidbody or both? or totally somthing else? I just want to learn about foundations of it. I have a idea but it sounds like it will destroy performance. Creating and destroying rays constantly to curve it or disabling an objects collider and mesh and adding a raycast to it to detect collision. What should I do.
Replies
There is some bullet physics packages on the asset store for not too expensive that you might check out, just to get ideas. Or, you could check out the Arma modkit. About performance, no need to write anything off as too expensive if you don't already have lots of experience with the subject. Prototype your ideas, then you'll know.
It's pretty straightforward. It has an initial velocity, at every tick that's reduced by an amount of drag and then you move it downward by the influence of gravity. Calculating the correct vector is a simple Google away
If you need a specific unity implementation you'll find one on their forums
And, of course, you can get way more complicated than that, but for a "realistic" game, taking account of windage, elevation, and bullet flight path characteristics is more than enough. Actually, I don't think arma has specific flight path characteristics for different calibers, and that is probably a good thing. Even a video game purported to be realistic still has to be a game first, i.e. it has to be fun. And something that seems random won't be much fun. If you get too realistic, you are getting into things the player will not be able to see or understand and additionally this level of complexity will eat up your programming time, and the only returns will be players thinking the game is to random.
Anyway, if you want to get a quick crash course in bullet physics, just google or youtube. I'd make sure its some kind of reputable source though. Lots of gun-nuts out there espousing all sorts of crazy urban legend type of stuff. Once you know enough about that it should be obvious how to implement it into code. Well, enough to make a rough plan for a prototype anyway. If not, that's probably a good indication that you need more experience coding basic things, and for that, if you haven't done the great tutorial game projects in the Unity learn section, I'd start there. Also check out a free tutorial on youtube called Gamer to Game Developer that will step-by-step show you how to build an entire FPS game.
By and large it'll be some basic physics calculations (gravity, deceleration).
Then you're just feeding in the time since firing and taking where it was last frame and where it is this frame and you can raycast between those points.
I imagine that generally it'll be moving fast enough that a straight line between frames will get you a decent result but you might want to rig it up to do samples at fixed time intervals and raycast each one in turn for a more consistent result.
In this video, when they shoot through the walls, it looks like multi-ray cast. The bouncing one could be done with projectiles.