# Are Battlefield 4/Max Payne 3 hitscan or projectile based?

I am trying to figure out how battlefield 3/4 does bullet drop and target leading.

I am also wondering how Max Payne 3 showed bullets in flight during bullet time (slow mo).

Bf4/3 I have no clue about.

I assume MP3 does a raycast from the camera and then fires an actual projectile to where that Raycast hit but I’m not sure.

Anyone have any wisdom to spread on this topic.

Probably some math involved in the raycasting process of firing the gun. To simulate an actual projectile being fired. Ive done this before. Raycast once, second time however, simulate bullet drop with rotating the direction of the second raycast, and, apply a delay to the second raycast( i know it sounds hacky ).

For that kind of thing I personally do a mixture - projectiles which use raycasts. Each tick, calculate the new direction and raycast in that direction as far as the projectile should travel in a single tick. If it hits nothing, move to that spot. Otherwise, move to where it hit.

Ahh so that is what bf devs mean by tick rate?(aka how often a bullet checks for a hit with its own raycast)

So, let me get this straight. You hit fire and the bullet moves to a Ray cast point ahead of the muzzle, then it raycasts again and then moves to that spot. Repeat until it hits the ground or player. No force is applied to the bullet prefab?

How do you slow a bullet down like in borderlands? Would you need to use physics and force to do that?

Well, “physics” and “force” are just “rules we apply in code to make things look like they’re behaving realistically”, right? So yes, you “apply physics”, but that probably means writing your own simple rules which you can tweak for various projectiles. In this case it probably doesn’t mean using your off-the-shelf physics library, though I guess some might have built in functionality for this kind of thing, as it’s common enough.

Also, “tick rate” is how often the game’s back end updates what’s going on. It’s not just bullets, it’s everything.

I think Max Payne bullets was real physics objects with no gravity assigned.
That’s the simplest way. Of course, you would have to destroy every bullet on collision to have resources.

For BF3, I could swear it’s the same thing. When I shoot a sniper, I can see the bullet travel and drop onto the enemy’s head, headshot.
It could be a mixture of both depending on distance. Long shot = physics object, close range = raycast since it wouldn’t make a difference.

I could be wrong about BF3.

Ok so I got it working about 50% of the time in engine. The problem I have is that for fast moving projectiles (like a bullet) the tick times need to be lower than unity allows. Therefore a lot of the bullets pass through colliders because its in between raycasts.

Is there anyway to get around this? I have tried offsetting a second raycast and it helped some but projectiles still leak through. If I set the range of the raycast higher to compensate it causes unnatural flight behavior.

Is using Linecast a possibility?

There is a script called “DontGoThroughThings” on the wiki. Add it to your bullet and it will check every frame if it went through something and if yes, change position to the hit point.

Here’s how I imagine doing bullet drop in a realistic way without making physics / a projectile.

Raycast from your gun (or whatever) first some distance. Then, raycast again from the distance where the bullet begins to drop. Continually do this with the direction angling downward until it hits something. You can have the distance before the new drop angle be determined by the gun stats. A sniper rifle will go further before the “projectile” angles downward. In an ideal situation with a round world and a strong enough gun, you could send a ‘bullet’ into orbit around your project xP

You dont need to have an actual projectile, you could just have a raycast, and to simulate the bullet travel that is seen in bf3, you could use a line renderer.