How do video game bullets and projectiles work?

General discussion of the Project Reality: BF2 modification.
MrDow123
Posts: 65
Joined: 2007-08-08 17:10

How do video game bullets and projectiles work?

Post by MrDow123 »

I've wondered this question for years and years and could never figure out an answer.

How do video game projectiles work? How do you get trajectory and tracers to actually work in PR? When you click the left mouse button to fire your weapon, how do the bullets reach the target?

Could someone please explain this to me? I know how bullets work in real life because I use bullets to hunt big game at long range, so I have to know trajectory and velocity, but I dont understand how it works in the game world
Steve: "I've got an M4 attached with an ACOQ Reflex sight, an M203 Grenade Launcher, a 4X power scope, a bipod, a massive night vision scope, a flashlight, a lazer pointer, a suppressor, a drum magazine, and a cappuccino maker"
Dan: "Mhmm, interesting. And how much does the gun weigh? Whats the recoil like? How accurate is it?
Steve: "About 50 pounds, it broke my shoulder when I fired it, and it couldn't hit the broad side of a barn. But it sure looks cool"
blud
Posts: 1246
Joined: 2006-09-04 22:22

Post by blud »

In most games the bullet doesn't travel, and there actually is no bullet. When you fire on someone it just immediately registers a hit on them, on anything that is in the path of where your gun is pointing.

But in PR/BF I *guess* the bullets are proper projectiles? In which case I can only assume that basically the bullet becomes an entity in the game, just like a tank or a soldier, and the bullet flys across the map to its destination.. but.. someone else might know this for sure.
vibes
Posts: 43
Joined: 2007-07-17 23:13

Post by vibes »

good question :p love to see a dev or someone knowledgable about such things answer this.
Paladin-X
Retired PR Developer
Posts: 592
Joined: 2005-06-12 16:00

Post by Paladin-X »

When a weapon is fired a projectile object is created. The path and speed are calculations done by the game. We can modify those variables that will affect those calculations in the code. For example we can define the speed by this line: ObjectTemplate.velocity 925. (925 meaning meters per second I believe). We can modify trajectory with the 'cone of fire' and change gravity variables as well.

Gravity:
ObjectTemplate.gravityModifier 0.3

'Cone of fire' (Path deviation)
ObjectTemplate.deviation.minDev 0.15
ObjectTemplate.deviation.setFireDev 0.7 0.2 0.05
ObjectTemplate.deviation.setTurnDev 1.5 0.2 0.2 0.1
ObjectTemplate.deviation.setSpeedDev 2.55 0.2 0.1 0.12
ObjectTemplate.deviation.setMiscDev 4.8 2.5 0.1
ObjectTemplate.deviation.devModStand 1.1
ObjectTemplate.deviation.devModCrouch 0.6
ObjectTemplate.deviation.devModLie 0.3
ObjectTemplate.deviation.devModZoom 0.4

I don't remember exactly what each number represents, so unfortunately I can't explain that one further.

Also, with BF2 the path of the bullet is calculated like 30 times per second or something like that (I don't remember the exact number). The bullet will end if there is a collision or will expire (disappear) as per the timetolive setting. With BF2, some bullets have a penetration property as well, so that it may not necessarily stop on collision. As well as a ricochet property that can send the bullets bouncing around.

As for tracers... we can make these otherwise invisible bullets show up by setting the tracer properties. We can define the size, when it will fire (ex every 5th bullet) and colour. Here are some properties of tracers:

ObjectTemplate.tracerScaler 20
ObjectTemplate.maxTracerScaler 30
ObjectTemplate.minTracerScaler 10
ObjectTemplate.tracerSizeModifier 5
ObjectTemplate.tracerConvergeDistance 20
ObjectTemplate.tracerTemplate p_tracer_r
ObjectTemplate.tracerInterval 5

NOTE: Some weapons have actual modelled projectiles, such as the M203.
Image
Image
PlatinumA1
Posts: 381
Joined: 2007-06-25 07:31

Post by PlatinumA1 »

yeah i was about to say , last night my computer froze while playing pr and a apc was in my face shooting , i saw the projectile, it looked like a shooting star
Dunehunter
Retired PR Developer
Posts: 12110
Joined: 2006-12-17 14:42

Post by Dunehunter »

Most games seem to do the "determine where the bullet goes and what's in its way" thing, but there are others, like Supreme Commander, where every projectile becomes an entity on its own.
Expendable Grunt
Posts: 4730
Joined: 2007-03-09 01:54

Post by Expendable Grunt »

I actually posted over at game dev about making a "physics gun" that actually has a magazine full of bullet models that actually fly out of the gun based on a physics model similar to blowing up a grenade next to something in HL2 -- uses the explosion and containment to fing it the right way.
Image


Former [DM] captain.

The fact that people are poor or discriminated against doesn't necessarily endow them with any special qualities of justice, nobility, charity or compassion. - Saul Alinsky
El_Vikingo
Posts: 4877
Joined: 2006-11-27 01:50

Post by El_Vikingo »

From what I understood from Eggmans post about how bullets travelled in BF2:

The bullets go straight and then drop off at the designated range the rifle was zeroed into. In real life the bullet would travel upto reach further distances.

Image
Image

If you are reading this dont stop, cause if you do, I'll kick you in the balls.
Katarn
Retired PR Developer
Posts: 3358
Joined: 2006-01-18 22:15

Post by Katarn »

Actually vikingo, bf2's would be a perfectly straight line because it's linear. As soon as the projectile leaves the weapon, it goes in a perfectly straight linear drop.
El_Vikingo
Posts: 4877
Joined: 2006-11-27 01:50

Post by El_Vikingo »

Straight out? So theres no bullet drop at all?
Image

If you are reading this dont stop, cause if you do, I'll kick you in the balls.
KingofCamelot
Retired PR Developer
Posts: 2365
Joined: 2006-01-07 18:17

Post by KingofCamelot »

Paladin-X explained it pretty well, but I'll also note that DICE used basic high school physics equations throughout the game.

While playing around with the mortar the other day in the editor I could do some simple math and calculate at what distance the round was going to land. Was kinda cool. :)

Only oddity you have to account for is that DICE used 14.8 m/s*s as gravity in-game, instead of the 9.8 m/s*s in real life. Not sure why they did that tbh.
Ruthless Executioner of 280 SpamBots
Image
Retired Lead Coder for Project Reality - 0.25 through 0.4
tupla_s
Posts: 145
Joined: 2007-05-24 17:14

Post by tupla_s »

[R-DEV]Katarn wrote:Actually vikingo, bf2's would be a perfectly straight line because it's linear. As soon as the projectile leaves the weapon, it goes in a perfectly straight linear drop.
You mean like in a or b?
Image
Image
Jaymz
Retired PR Developer
Posts: 9138
Joined: 2006-04-29 10:03

Post by Jaymz »

B
"Clear the battlefield and let me see, All the profit from our victory." - Greg Lake
Expendable Grunt
Posts: 4730
Joined: 2007-03-09 01:54

Post by Expendable Grunt »

14.8m/s^2? wtf...
Image


Former [DM] captain.

The fact that people are poor or discriminated against doesn't necessarily endow them with any special qualities of justice, nobility, charity or compassion. - Saul Alinsky
requiem
Retired PR Developer
Posts: 3651
Joined: 2004-07-22 16:00

Post by requiem »

Tupla got it right with B. Too complex bullet physics could create some serious lag.
Katarn
Retired PR Developer
Posts: 3358
Joined: 2006-01-18 22:15

Post by Katarn »

Doesn't in ArmA and flashpoint requiem. And flashpoint is oldschool, processing power was definitely not up to where it is today :) .
MrDow123
Posts: 65
Joined: 2007-08-08 17:10

Post by MrDow123 »

Thanks for the answeres DEV's and Members :)
Steve: "I've got an M4 attached with an ACOQ Reflex sight, an M203 Grenade Launcher, a 4X power scope, a bipod, a massive night vision scope, a flashlight, a lazer pointer, a suppressor, a drum magazine, and a cappuccino maker"
Dan: "Mhmm, interesting. And how much does the gun weigh? Whats the recoil like? How accurate is it?
Steve: "About 50 pounds, it broke my shoulder when I fired it, and it couldn't hit the broad side of a barn. But it sure looks cool"
El_Vikingo
Posts: 4877
Joined: 2006-11-27 01:50

Post by El_Vikingo »

Why twice the amount of it in RL? Can you guys change this amount? If so, would it change the gravity to low gravity, so to say?
Image

If you are reading this dont stop, cause if you do, I'll kick you in the balls.
Leo
Posts: 2082
Joined: 2006-11-29 00:40

Post by Leo »

maybe that's why planes drop like a rock instead of gliding?
KingofCamelot
Retired PR Developer
Posts: 2365
Joined: 2006-01-07 18:17

Post by KingofCamelot »

El_Vikingo wrote:Why twice the amount of it in RL? Can you guys change this amount? If so, would it change the gravity to low gravity, so to say?
Its not twice, its about 1.5x. :razz:

Like I said, no idea why they have it set to that, but thats how the game is configured. Changing it now would make it seem like low gravity, and cause everything to go to shit. :)

Not really a big deal, you never even knew. ;)
Ruthless Executioner of 280 SpamBots
Image
Retired Lead Coder for Project Reality - 0.25 through 0.4
Post Reply

Return to “PR:BF2 General Discussion”