• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ElganSayer

2D Parabolic Arc between dynamic A-B

2 posts in this topic

Hello,
I have a problem and I'm not smart enough to work out a solutions.

I want to achieve a throw, a bomb between two points, and so it travels as an arc from point A, to point B. [b]Point B is known and the bomb must land on point B[/b]


if the distance between the two positions AB is dynamic and the horizontal distance changes, the vertical distance may also change.


How can we know the initial vertical velocity in which to throw the object to make it art exactly on to position B?

How can I calculate it so my bomb moves in an arc from whatever point A is, so that it hits point B in an ARC. I have no idea, using other istes this is what I tried, i tried at least...then realized I have no idea for how long to run the loop for, and have no idea how to hit point b exactly.

tagetTilePosition is a vector ( 0 , 0 )
[code]
double startX = bombPosition.x; // initial position
double startY = bombPosition.y; // of the object
float angle = 45.0f * Mathf.Deg2Rad;
const double g = 9.8; // gravity (meters/s^2)
double velocity =20.0;
double Vx = velocity * Mathf.Cos(angle); // x (horizontal) component of velocity
double Vy = velocity * Mathf.Sin(angle); // y (vertical) component of velocity

Vector2 distance = ( bombPosition2 - tagetTilePosition );

//guessing
double endTime = ( distance.x + distance.y ) / velocity ;

for(double wait = 1; wait <= endTime ; wait += 1f)
{
/*
float v_v;
double g = 9.8f
float s;
float t = wait;

s = bombPosition.y;
t = d / v_h
v_v = (0.5f * g * (t * t) + s) / t;
*/
double t = wait;
double x = startX + Vx * t;
double y = startY + Vy * t - 0.5 * g * t * t;
bombPosition.x = (float) x;
bombPosition.y = (float) y;

// bombPosition.x = centre.x += ( 60 * Mathf.Cos ( (float) wait ) );
//bombPosition.y = centre.y -= ( 60 * Mathf.Sin ( (float) wait) );

bomb.transform.position = bombPosition;
}
[/code]
0

Share this post


Link to post
Share on other sites
Assuming gravity is the only force on the bomb, and is strictly downwards, and that point [eqn]B[/eqn] does not move while the bomb is in the air (obviously) and that there are no obstacles to consider, then you can in fact work out the exact initial velocity vector needed to hit point [eqn]B[/eqn]. First, let [eqn]A[/eqn] be at coordinates [eqn](a_x, a_y)[/eqn] and [eqn]B[/eqn] at coordinates [eqn](b_x, b_y)[/eqn].

Then, using some kinematics, the position of the bomb at any time [eqn]t[/eqn] will be:

[eqn]\displaystyle \left (a_x + v_x t, ~ a_y + v_y t + \frac{1}{2} g t^2 \right )[/eqn]

So for the bomb to hit [eqn]B[/eqn] somehow, we need the coordinates of the bomb to satisfy:

[eqn]a_x + v_x t = b_x[/eqn]
[eqn]a_y + v_y t + \frac{1}{2} g t^2 = b_y[/eqn]

For some [eqn]t[/eqn]. Rearranging:


[eqn]v_x = \frac{b_x - a_x}{t}[/eqn]
[eqn]v_y = \frac{b_y - a_y- \frac{1}{2} g t^2}{t}[/eqn]

Simplifying:

[eqn]v_x = \frac{b_x - a_x}{t}[/eqn]
[eqn]v_y = \frac{b_y - a_y}{t} - \frac{1}{2} g t[/eqn]

This is a parametric equation in [eqn]t[/eqn], which basically gives a bigger and bigger velocity vector as you decrease the time (the faster you shoot, the less time gravity has to effect the bomb, so at infinite speed you can pretty much just aim towards B and shoot). As you increase the time [eqn]t[/eqn], gravity becomes more important (see the gravity term in the equation) and the direction itself matters less, so you get an increasingly large arc. Here's a rough plot of the parametric I made with a throwaway program:

[img]http://i47.tinypic.com/o9jn2t.png[/img]

If you need the bomb to stay a certain amount of time in the air, just plug the correct [eqn]t[/eqn] in, and you have your velocity vector! If you need your velocity vector to be a certain length (for instance, the amount of force with which the bomb is launched), you can use that information to deduce [eqn]t[/eqn] as well. You could also calculate the energy requirements for a given [eqn]t[/eqn] and compare them with whatever energy your bomb cannon has to select the correct one, if you wanted to get really fancy.

[b][u]N.B.[/u][/b] This can be generalized to any gravity vector and to higher dimensions by modifying the kinematics accordingly, but for the sake of simplicity and without loss of generality, only gravity in the vertical direction for the two-dimensional case is considered. Edited by Bacterius
2

Share this post


Link to post
Share on other sites
For completeness, I provide the fully generalized version in this post (since I guess someone will eventually ask). Let [eqn]\bold{A}[/eqn] be the initial position vector [eqn]\left ( \mathrm{A}_1, \mathrm{A}_2, \cdots, \mathrm{A}_n \right )[/eqn] and [eqn]\bold{B}[/eqn] the final position vector [eqn]\left ( \mathrm{B}_1, \mathrm{B}_2, \cdots, \mathrm{B}_n \right )[/eqn]. We want to find an initial velocity vector [eqn]\bold{v} \left ( v_1, v_2, \cdots, v_n \right )[/eqn] such that a projectile fired from [eqn]A[/eqn] with this velocity vector will collide with [eqn]B[/eqn] when subject to some constant force [eqn]\vec{F}[/eqn] producing an acceleration [eqn]\bold{a} \left (a_1, a_2, \cdots, a_n \right )[/eqn] on it. Note if the projectile has mass [eqn]m[/eqn], then [eqn]\vec{F} = m \bold{a}[/eqn] as expected.

Let [eqn]\bold{P}_t \left (\mathrm{P}_{1, t}, \mathrm{P}_{2, t}, \cdots, \mathrm{P}_{n, t} \right )[/eqn] be the position of the projectile at time [eqn]t[/eqn] after launch. Then from kinematics, for [eqn]1 \leqslant i \leqslant n[/eqn] we have:

[eqn]\mathrm{P}_{i, t} = \mathrm{A}_i + v_i t + \frac{1}{2} a_i t^2[/eqn]

And for the projectile to collide with [eqn]\bold{B}[/eqn], its position must satisfy [eqn]\bold{P}_t = \bold{B}[/eqn] for some time [eqn]t \geqslant 0[/eqn], so:

[eqn]\mathrm{B}_i = \mathrm{A}_i + v_i t + \frac{1}{2} a_i t^2[/eqn]

[eqn]v_i t = \mathrm{B}_i - \mathrm{A}_i - \frac{1}{2} a_i t^2[/eqn]

[eqn]\displaystyle v_i = \frac{\mathrm{B}_i - \mathrm{A}_i}{t} - \frac{1}{2} a_i t[/eqn]

Yielding a family of solutions for [eqn]\bold{v}[/eqn] for any positive [eqn]t[/eqn]. Negative [eqn]t[/eqn] works too, but it makes little sense since the intersection would have occurred before the projectile was launched, extrapolating its trajectory into the past - though you will notice flipping the sign of [eqn]t[/eqn] flips the sign of [eqn]v_i[/eqn] and thus simply inverts the direction of [eqn]\bold{v}[/eqn] anyway. This is a very nice and flexible result.

--------------------------------

What about nonconstant forces? Suppose [eqn]\vec{F}[/eqn] varies with time, so [eqn]a_i = f_a(i, t)[/eqn]. The force/mass relationship still works, of course. Perhaps this could take into account gravity as well as wind (possibly via some sinusoidal function to simulate atmospheric fluctuations). Can we still predict the correct velocity vector? The answer is, surprisingly, yes, but we must use calculus. We must integrate this acceleration function with respect to time once to obtain velocity, and once again to obtain displacement, which results in the following trajectory for [eqn]P_t[/eqn]:

[eqn]\displaystyle \mathrm{P}_{i, t} = \mathrm{A}_i + v_i t + \int_0^t \int_0^t f_a(i, t)\, \mathrm{d} t\, \mathrm{d} t[/eqn]

With the same criterion as before, this gives:

[eqn]\displaystyle \mathrm{B}_i = \mathrm{A}_i + v_i t + \int_0^t \int_0^t f_a(i, t)\, \mathrm{d} t\, \mathrm{d} t[/eqn]

And rearranging as we did before:

[eqn]\displaystyle v_i = \frac{\displaystyle \mathrm{B}_i - \mathrm{A}_i}{t} - \frac{\displaystyle \int_0^t \int_0^t f_a(i, t)\, \mathrm{d} t\, \mathrm{d} t}{t}[/eqn]

Which, interestingly enough, is a parametric solution in [eqn]t[/eqn]. Now, actually evaluating the double integral is probably the hardest part, especially if you're using some complex function such as perlin noise as the acceleration, but if worst comes to worst, approximations exist. Besides, it's likely your predicted trajectory doesn't have to be perfect, but just close enough.

Let's try and pick some relatively simple time-varying function and see if it works. For instance, let's say in our hypothetical world, gravity is modulated by a sinusoidal function. Kind of weird, but hey. So for instance, we have [eqn]f_a(i, t) = a_{i, 0} \sin{t}[/eqn]. Then the double integral is easy enough to calculate (remember those are definite integrals):

[eqn]\displaystyle\int_0^t \int_0^t f_a(i, t)\, \mathrm{d} t\, \mathrm{d} t = a_{i, 0} \left ( t - \sin{t} \right )[/eqn]

So let's plug everything into our parametric equation and see what we get:

[eqn]\displaystyle v_i = \frac{\mathrm{B}_i - \mathrm{A}_i}{t} - a_{i, 0} \left ( 1 - \frac{\sin{t}}{t}} \right )[/eqn]

The resulting trajectory for some [eqn]t[/eqn] is illustrated below:
[img]http://i46.tinypic.com/34srxub.png[/img]

What about a different time-varying function, let's say [eqn]f_a(i, t) = a_{i, 0} \left ( 1 - \sin^2{\pi t} \right )[/eqn]. Then the double integral is more complicated but still tractable:

[eqn]\displaystyle\int_0^t \int_0^t f_a(i, t)\, \mathrm{d} t\, \mathrm{d} t = a_{i, 0} \frac{1}{8} \left ( 2t^2 + 1 - \cos{2 \pi t} \right )[/eqn]

Which gives the following trajectory for some [eqn]t[/eqn] (this is [i]not[/i] a parabola):
[img]http://i49.tinypic.com/25fh7iv.png[/img]

--------------------------------

Note if [eqn]f_a(i, t) = a_{i, 0}[/eqn], then the double integral becomes [eqn]\frac{1}{2} a_{i, 0} t^2[/eqn], and we get back the familiar kinematics equation. If [eqn]f_a(i, t) = 0[/eqn] then you just get back [eqn]\bold{v} = \frac{\bold{d}}{t}[/eqn] as you would expect. It's also possible to make the force vary on position instead of just time, but you need more integrals and it just gets messy and tedious to calculate, so we'll leave it at that.

--------------------------------

Additional note: if [eqn]\mathrm{B}[/eqn] happens to be moving, you can also take that into account (isn't math wonderful) by changing the [eqn]\mathrm{B}_i[/eqn] term - which is a position - into a function of time [eqn]t[/eqn]. If you want a [i]time-varying force[/i] to be applied to [eqn]\mathrm{B}[/eqn], you can use the same methods as above, which involve another double integral. However at this point, the problem essentially boils down to finding a parameterized intersection of two differential curves, which might be better tackled by other methods involving more specialized forms of calculus. Edited by Bacterius
2

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0