What are the formulas which represent the horizontal and vertical displacement of an arrow in flight (as well as it angle)? I would like to make sure that I take into consideration the arrow's fluid dynamics and center of gravity.
-
1\$\begingroup\$ gamedev.stackexchange.com/questions/13924/… \$\endgroup\$– JoelCommented Jun 20, 2011 at 13:50
-
\$\begingroup\$ Are you talking for general equations of motion of particles being projected under the effect of gravity? \$\endgroup\$– PrettyPrincessKitty FSCommented Jun 20, 2011 at 13:52
-
4\$\begingroup\$ If this is a game development question, I'd say that you shouldn't care about the exact formulae, we just want to have something that looks like an arrow, which is rather simple. If you want real-time simulation than you first need to tell us the length of the arrow, the weight, the amount and position of feathers, etc... \$\endgroup\$– Jonathan ConnellCommented Jun 20, 2011 at 14:17
-
1\$\begingroup\$ Are you trying to simulate a REAL arrow flight, or just a "cartoon" arrow? Real arrows have a lot of interesting physics beyond just a simple parabola. \$\endgroup\$– Tim HoltCommented Jun 20, 2011 at 17:27
2 Answers
I actually answered this in your other question, but since this one is here, this is the place to do it cleanly on its own.
What you are asking is the trajectory problem. First, consider it neglecting air friction.
For an initial velocity v0 and angle a
v0x = v0 * cos(a)
v0y = c0 * sin(a)
for velocities as a function of time:
vx = v0x
vy = v0y - g * t
You need a reality check if you think you are going to handle instability, tumbling, or anything like that. You don't have the math for it, and it will take years to get it right, as well as massive amounts of CPU you don't want to devote in a game. You can try to fake that if you like. But if you want somewhat realistic slowing down of the projectile, that's relatively easy.
v = sqrt(vx*vx+vy*vy)
a = c * v*v*v
The coefficient c is a small number, and friction will tend to slow down the projectile so it always operates in the opposite sign of the moving projectile. You need the direction of the projectile, which is the vector:
(vx, vy)
but this is scaled according to the velocity. If you want to apply a negative acceleration, first compute the magnitude (already computed as v above)
Now you can generate a vector 1 unit long in the direction of the projectile:
(vx/v, vy/v)
to apply the acceleration in reverse:
-a * vx/v, -a * vy/v
This will have the effect of slowing down the projectile and making it fall short of what it would do with no air friction. the higher your constant c, the shorter the trajectory.
If you have wind, then just add to vx in your 2d game, in either + or - direction.
If you really want to show the projectile tumbling once it moves slowly enough, ask another question, but that will be a discussion of how to fake it, not how to do the real physics.
If you want to see just what you are getting yourself in for with simulating the drag on a projectile, this should be a survey paper that will show you the different approaches out there. http://raphael.mit.edu/peraire/SequeiraWillisPeraire.pdf
-
\$\begingroup\$ actually, looking at the paper in more detail, it is way simpler than what you want, because all those methods only work for limited cases, for a projectile tumbling you probably need a full CFD code, let's just say it's completely impractical, but I like the approach below. \$\endgroup\$– DovCommented Jun 20, 2011 at 19:00
-
\$\begingroup\$ "You need a reality check if you think you are going to handle instability, tumbling, or anything like that" - Actually, the differential equations that describe these things are easy to work in video games, because they tell you exactly how each variable changes each frame. They are difficult to work with in physics simulations, where you care about small rounding errors propagating over time; and difficult in mathematics, where you want to work with closed-form solutions; but video-game programmers don't care about either of those things. \$\endgroup\$ Commented Jun 20, 2011 at 19:14
-
\$\begingroup\$ ok, so taking @Gajet's idea, but in reverse, if you want to create a tumbling arrow once it's going slow enough, do what I said twice, making the arrow head drag slightly higher than the tail. That will induce rotation, and you'll need to keep track of rotational inertia and energy. It would also be a good idea to sharply increase drag coefficient of the head as it turns away from the pointy direction. \$\endgroup\$– DovCommented Jun 20, 2011 at 19:32
the simplest form you can simulate it is to use two weights connected to each other with a spring, resembeling head and tail of the arrow. and you have to just give the following object a little more thrust that the heading one to cause the arrow move like a real one, it just needs some tuning before it get's well, but it'll create a realistic movement. you can also make some diffrences for other parameters of head and tail weights, for example tail object has more air friction than the head one.
-
\$\begingroup\$ This is a good starting point, but if you just want to induce drag, you don't need it, and if you want to make the arrow start tumbling once it goes slow enough, it won't work. \$\endgroup\$– DovCommented Jun 20, 2011 at 19:12
-
\$\begingroup\$ @dov: you can also simulate tumbling by some speed triger to suddenly change speed, I don't think that's a big deal. \$\endgroup\$– Ali1S232Commented Jun 20, 2011 at 20:22