Mortar Ballistics
by David Smith · in Technical Issues · 03/03/2006 (10:46 pm) · 10 replies
I have been working on this problem for some time now, and I have gotten nowhere. Consider a mortar in a FPS game, where the distance and height difference between the 2 entities are known variables. What I have so far is:
angles[YAW] --- left right [0...360] degrees
angles[PITCH] --- up down [0...90] degrees
angle = angles[YAW] * (M_PI * 2 / 360)
sy = sin(angle)
cy = cos(angle)
angle = angles[PITCH] * (M_PI * 2 / 360)
sp = sin(angle)
cp = cos(angle)
forward[0] = cp * cy
forward[1] = cp * sy
forward[2] = -sp
forward[0] = forward[0] * 3300
forward[1] = forward[1] * 3300
forward[2] = forward[2] * 1650
Length of this vector is the speed of the projectile. In the calculation the speed of the projectile is different at different angles. You will notice that the speed is not depended on YAW angle but only on PITCH angle. The speed goes from 1650 at PITCH of 90 degrees and to 3300 at PITCH of 0 degrees. All the middle values are determined by the upper formulas. Hopefully all this can be simplified so YAW angle won't be in the equation. The launch speed is determined by the angle, so basically it is another variable and not a constant in the calculations. So, would the following equation be correct : launch_speed = sqrt [3300^2 * cos^2(PITCHangle) + 1650^2 * sin^2(PITCHangle)]. Hope it is right I just did it by heart. And of course this can be reduced down to use only cos or sin. The following equations were my initial ones I was using :
v_o is the velocity of the projectile
v_x(t) is the x speed at time t
v_y(t) is the y speed at time t
theta is the launch angle
h is the maximum height of the projectile
b is the landing height of the projectile
R is the total distance traveled in x
Formulas for targets higher than the launch point
x(t) = v_o * cos(theta) * t
y(t) = v_o * sin(theta) * t
v_x(t) = v_o * cos(theta)
v_y(t) = v_o * sin(theta) - g * t
v(t) = sqrt(v_o^2 - 2 * g * t * v_o * sin(theta) + (g * t)^2)
h = (v_o^2 * sin(theta)^2) / 2 * g
R = v_o * T * cos(theta)
T = (v_o * sin(theta) / g + sqrt(2 * (h - b) / g)
Formulas for targets lower than the launch point
x(t) = v_o * cos(theta) * t
y(t) = v_o * sin(theta) * t
v_x(t) = v_o * cos(theta)
v_y(t) = v_o * sin(theta) - g * t
v(t) = sqrt(v_o^2 * 2 * g * t * v_o * sin(theta) + (g * t)^2)
h = b + (v_o^2 * sin(theta)^2) / (2 * g)
R = v_o * T * cos(theta)
T = (v_o * sin(theta) / g + sqrt( 2 * h / g)
For horizontal motion ->
Horizontal velocity =
a_x = 0
v_x = v_ox
Horizontal distance =
x = v_ox * t
For vertical motion ->
Vertical velocity =
a_y = -g = 9.8 m/s^2
v_y = v_oy - g * t^2
Vertical position =
y = v_oy * t - 0.5 * t^2
angles[YAW] --- left right [0...360] degrees
angles[PITCH] --- up down [0...90] degrees
angle = angles[YAW] * (M_PI * 2 / 360)
sy = sin(angle)
cy = cos(angle)
angle = angles[PITCH] * (M_PI * 2 / 360)
sp = sin(angle)
cp = cos(angle)
forward[0] = cp * cy
forward[1] = cp * sy
forward[2] = -sp
forward[0] = forward[0] * 3300
forward[1] = forward[1] * 3300
forward[2] = forward[2] * 1650
Length of this vector is the speed of the projectile. In the calculation the speed of the projectile is different at different angles. You will notice that the speed is not depended on YAW angle but only on PITCH angle. The speed goes from 1650 at PITCH of 90 degrees and to 3300 at PITCH of 0 degrees. All the middle values are determined by the upper formulas. Hopefully all this can be simplified so YAW angle won't be in the equation. The launch speed is determined by the angle, so basically it is another variable and not a constant in the calculations. So, would the following equation be correct : launch_speed = sqrt [3300^2 * cos^2(PITCHangle) + 1650^2 * sin^2(PITCHangle)]. Hope it is right I just did it by heart. And of course this can be reduced down to use only cos or sin. The following equations were my initial ones I was using :
v_o is the velocity of the projectile
v_x(t) is the x speed at time t
v_y(t) is the y speed at time t
theta is the launch angle
h is the maximum height of the projectile
b is the landing height of the projectile
R is the total distance traveled in x
Formulas for targets higher than the launch point
x(t) = v_o * cos(theta) * t
y(t) = v_o * sin(theta) * t
v_x(t) = v_o * cos(theta)
v_y(t) = v_o * sin(theta) - g * t
v(t) = sqrt(v_o^2 - 2 * g * t * v_o * sin(theta) + (g * t)^2)
h = (v_o^2 * sin(theta)^2) / 2 * g
R = v_o * T * cos(theta)
T = (v_o * sin(theta) / g + sqrt(2 * (h - b) / g)
Formulas for targets lower than the launch point
x(t) = v_o * cos(theta) * t
y(t) = v_o * sin(theta) * t
v_x(t) = v_o * cos(theta)
v_y(t) = v_o * sin(theta) - g * t
v(t) = sqrt(v_o^2 * 2 * g * t * v_o * sin(theta) + (g * t)^2)
h = b + (v_o^2 * sin(theta)^2) / (2 * g)
R = v_o * T * cos(theta)
T = (v_o * sin(theta) / g + sqrt( 2 * h / g)
For horizontal motion ->
Horizontal velocity =
a_x = 0
v_x = v_ox
Horizontal distance =
x = v_ox * t
For vertical motion ->
Vertical velocity =
a_y = -g = 9.8 m/s^2
v_y = v_oy - g * t^2
Vertical position =
y = v_oy * t - 0.5 * t^2
#2
03/04/2006 (11:00 am)
Ok, Tim I understand. My problem is that, in my FPS, the velocity varies according to the angle of fire. I was looking for something that would give me AOF, but because of the variable speed I don't know if that is possible. Thanks
#3
03/04/2006 (5:36 pm)
Not sure what you mean by varying the velocity according to the angle of fire. The equations would certainly be difficult if there is some additional relationship between launch angle and launch speed. And the equations don't take into account the speed of the vehicle or the speed of the target either. So maybe there is room for a lot of improvement.
#4
angles[PITCH] --- up down [0...90] degrees
forward[1] = forward[1] * 3300 -> this projectile speed being at 0 degrees
forward[2] = forward[2] * 1650 -> this projectile speed being at 90 degrees
The speed goes from 1650 at PITCH of 90 degrees and to 3300 at PITCH of 0 degrees. All the middle values are determined by the upper formulas. So, speed is not a constant as in the real world.
03/04/2006 (6:22 pm)
As an example using my first post here: angles[PITCH] --- up down [0...90] degrees
forward[1] = forward[1] * 3300 -> this projectile speed being at 0 degrees
forward[2] = forward[2] * 1650 -> this projectile speed being at 90 degrees
The speed goes from 1650 at PITCH of 90 degrees and to 3300 at PITCH of 0 degrees. All the middle values are determined by the upper formulas. So, speed is not a constant as in the real world.
#5
03/04/2006 (7:29 pm)
Unless gravity isn't also a constant in your world, you can't hit any targets with that.
#6
03/04/2006 (11:25 pm)
LOL...yes sir gravity is a constant.
#7
03/05/2006 (5:14 am)
Good luck. I have no clue how this works.
#8
Even with a constant projectile speed "out of the barrel", ballistics physics are pretty complicated, so if you can make your projectile speed constant you'll be much better off.
03/05/2006 (6:08 am)
@David: I think what people are saying is that your assumption that your projectile speed should change based on firing angle isn't a good one...it's not realistic, and it makes for extremely complex (unsolvable?) ballistics equations.Even with a constant projectile speed "out of the barrel", ballistics physics are pretty complicated, so if you can make your projectile speed constant you'll be much better off.
#9
Also, in a game, players would probably think there's a bug if you implement any velocity dispersion from round-to-round. Things that will affect that are humidity, temperature, bore wear, number of rounds fired, weight variances on the ammunition, etc.
Intuitively, one would think that a mortar round maintains a generally uniform horizontal speed throughout its flight, but the horizontal speed decreases as it flies. This is largely due to the resistance in the air. One result of this is the falling angle is steeper than the rising angle. Air resistance means that the round's vertical speed doesn't decrease at the speed of gravity, it should vertically decelerate slightly more than the speed of gravity (gravity + air resistance) depending on the condition of the air, this also means that the accleration during decent would be slightly less than the speed of gravity (gravity - air resistance).
The 4.2" mortar in use by the US imparts a spin on the round, which causes it to drift a bit in flight. Think of this as being similar to a fade in golf. If you wanted to simulate this, the direction of the projectile should slowly drift to the right.
Players probably don't want to deal with that much complication, so a simplified physics model might be a good idea.
05/29/2007 (8:13 am)
I hope I don't sound too nitpicky, but a mortar is a fairly complicated weapon to aim. Unlike in Scorched Earth, you cannot finely adjust the power of the rounds, it's adjusted by charge packs. You need to use a round with proper charge-rating which affects it's initial velocity. That's probably far too much information for a game, but the point is that the round's weight and charge determine its initial velocity.Also, in a game, players would probably think there's a bug if you implement any velocity dispersion from round-to-round. Things that will affect that are humidity, temperature, bore wear, number of rounds fired, weight variances on the ammunition, etc.
Intuitively, one would think that a mortar round maintains a generally uniform horizontal speed throughout its flight, but the horizontal speed decreases as it flies. This is largely due to the resistance in the air. One result of this is the falling angle is steeper than the rising angle. Air resistance means that the round's vertical speed doesn't decrease at the speed of gravity, it should vertically decelerate slightly more than the speed of gravity (gravity + air resistance) depending on the condition of the air, this also means that the accleration during decent would be slightly less than the speed of gravity (gravity - air resistance).
The 4.2" mortar in use by the US imparts a spin on the round, which causes it to drift a bit in flight. Think of this as being similar to a fade in golf. If you wanted to simulate this, the direction of the projectile should slowly drift to the right.
Players probably don't want to deal with that much complication, so a simplified physics model might be a good idea.
#10
Edit: Ugh, I just noticed how old this thread is. Why do people update threads that are a year old? Surely he's solved his problem by now. Gawd.
06/17/2007 (6:13 pm)
Not to sound mean David, but it sounds like you're in desperate need of a high school physics book; your method of doing this doesn't make any sense to me. The velocity of the round shouldn't change depending on the angle the gun is fired. There are only two forces you really need to pay attention to during this; the force of the gun shooting the round, and gravity pulling the round downward. You separate the gun's push on the round into two separate forces; one for the force pushing up, and one for the force pushing in a horizontal direction. Don't ask me how, because I forget. I'll have to look it up soon myself I'm sure. All I remember is that it's extremely easy. Hahah. Anyway, good luck. Whenever you need formulas for physics....use physics formulas. That'll make your game realistic, and save you a whole lot of trouble trying to invent nonsensical math. X3Edit: Ugh, I just noticed how old this thread is. Why do people update threads that are a year old? Surely he's solved his problem by now. Gawd.
Torque Owner Tim Hutcheson
www.garagegames.com/mg/forums/result.thread.php?qt=35862