Hey, Domen here.
My task was and still is to create at least reasonable bullet logic which is “kinda” realistic. For starters lets define what a bullet is. For the first N metres (or any other unit) the bullet reacts and is defined as a raycast from an origin point to a direction – in most cases a gun barrel or the middle of the screen (crosshair position). If nothing is hit then proceed with so called partly raycasts – cast a short raycast and if nothing happens move the origin of the previous ray to an end position of that ray.
Here is an ugly paint sketch (:P):
This got me quite a satisfying result but I wasn’t happy with it. Bullet isn’t only a ray, it has a volume and there is also gravity that affects the movement of the bullet.
The next thing was to implement basic gravity impact to the bullet. I also moved every physics call to the FixedUpdate() so the Unity physics has the time to refresh itself. I also added a simple TTL (Time to live) system, so the bullet “dies” at about 25 raycasts.
Here is an example of an instant raycast (black ray) and the partly raycasts (red) which are affected by the gravity, kinda heavy bullet eh? The next stop was implementing the volume of the bullet, which is a simple raycast towards every directon. We can now change the gravity affection, bullet spread, bullet time to live and bullet speed, which is nice if we want to implement some sort of mortars, snipers, or weak pistols. Aaaaand the final result: