Page 1 of 3
How do video game bullets and projectiles work?
Posted: 2007-08-12 18:34
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
Posted: 2007-08-12 18:47
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.
Posted: 2007-08-12 18:52
by vibes
good question

love to see a dev or someone knowledgable about such things answer this.
Posted: 2007-08-12 19:06
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.
Posted: 2007-08-12 19:14
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
Posted: 2007-08-12 19:25
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.
Posted: 2007-08-12 19:39
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.
Posted: 2007-08-12 19:44
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.

Posted: 2007-08-12 19:55
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.
Posted: 2007-08-12 19:59
by El_Vikingo
Straight out? So theres no bullet drop at all?
Posted: 2007-08-12 20:11
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.
Posted: 2007-08-12 20:20
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?

Posted: 2007-08-12 20:52
by Jaymz
B
Posted: 2007-08-12 20:56
by Expendable Grunt
14.8m/s^2? wtf...
Posted: 2007-08-12 21:01
by requiem
Tupla got it right with B. Too complex bullet physics could create some serious lag.
Posted: 2007-08-12 21:07
by Katarn
Doesn't in ArmA and flashpoint requiem. And flashpoint is oldschool, processing power was definitely not up to where it is today

.
Posted: 2007-08-12 21:31
by MrDow123
Thanks for the answeres DEV's and Members

Posted: 2007-08-12 22:01
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?
Posted: 2007-08-12 22:05
by Leo
maybe that's why planes drop like a rock instead of gliding?
Posted: 2007-08-12 22:06
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.
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.
