Ballistics maths / targeting

Nomosoft

  • Posts: 122
I want to plot a projectile's path from A to B. This is to be used for AI actors to aim and fire at targets. The thing is, I don't understand the units used in gravity or linear damping. Obviously, I need to take both of these into account but are they pixels per frame/second/update, or some other measurement, entirely? Also, Flash seems to choke on any semi-serious math repeated in behaviors. Finally, there will (normally) be multiple viable paths for the projectile to take, so is it best to start with a launch velocity and calculate the curve from that?

If anyone can provide a working example of this type of targeting, I would really appreciate it.

Weasel8778

  • Posts: 236
You'd probably be over-complicating it by calculating actual projectile motion with gravity, angles, etc, not to mention the massive slow-down you'd get.

What type of a curve are you looking for? Most projectile curves can be replicated pretty well with basic mathematical functions.

Nomosoft

  • Posts: 122
I'm pretty sure I need to at least account for gravity. I would like to include wind or a constant damping effect. Also, I might want to aim over existing terrain, so I might need t calculate a curve that has height Y at position X.

If we assume a turn-based game, the calculation would only need to be done once per turn, so I am not sure slowdown will be a huge issue, but I'd have to prototype it to be sure.

What sort of approximations did you have in mind if I want to avoid the real math?

scubapk01

  • Posts: 38
I am working on similar idea in a game and would also like some ideas how to do this in a simple way with out over complication it.I was going to pull apart the Catapult and make a behavior from them that when I have time.
Any other ideas would be great too.

Thanks

t4u

  • Posts: 418
Equations:
YOu have speed of projectile(v) and angle(alfa)...
so:
Vy =cos(alfa)*V
Vx=sin(alfa)*V

H(t)=Vy*t-g*t^2/2
where g -is pwoer of gravity you just have to feel the right one

S(t)=Vx*t +/- Vwind * t
where + when you are shooting with wind
         - when you ar eshooting against it

check if it works...

Ps1:
If going pixel by pixel with those function woudl be too much i have aproximation idea but first check if any of written above makes sense.

Ps2:
Please dont have idea of changing air friction/shooting underwater
USE PICTURES WHEN YOU ASK SOMETHING!
If I helped you be sure to mention it in your game.

Tutorials + downloads:
http://t4upl.blogspot.com/

comport9

  • Posts: 51
Why do you need to calculate an actors firing at all? There's already behaviours that do this sorta thing.

Hectate

  • *
  • Posts: 4645
Comport9 is right that Box2D can handle nearly everything except for the actual choice of aiming it. That said, if you're really interested in handling your own ballistic physics, here's an excellent article I bookmarked for when I get around to doing an old-school artillery game (if you look at my WIP games you'll see there's a terrain generation test that I had been working on for just this purpose).

http://www.atarimagazines.com/startv5n2/physics.html

Obviously, as noted the tutorials are written in BASIC for Atari, but the formulas themselves are the same no matter what.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

scubapk01

  • Posts: 38
Hi all
Thanks for the extra input and ideas

But I am not sure if we are on the same page?
I was referring to projectile path in air like in catapult and ballon shooting games
I know there is the two push functions. Is that what you guys were referring to?

If not can you provide a link to info on what you were thinking about?

Thank you

dtrungle

  • Posts: 1938
I think the OP wants to calculate where the enemy AI will fire in the air in order to connect with a target at the ground, with regards to gravity and wind resistance.