Parabola/Tracjectory tracing with Physics / Box2D

0 favourites
From the Asset Store
Game for kids for tracing letters. A simple game for tracing letters.
  • So am making a tank game - the general gist is mostly working, the issues that remain are accurately predicting the arc of the shell, and getting the shell turning in the air as it goes through the arc.

    I had a search of the forums and turned up a few interesting things for top-down shadows on arrows and such, or solutions using canvas plugin to render an arc, but was hoping to avoid 3rd party plugins.

    Here's a basic idea of how it'd look.

    <img src="http://www.johnnysix.net/games/Recoil/Preview01.png" border="0">

    Test Game here -

    www.johnnysix.net/games/Recoil

    [ Artwork is just placeholder for now, I'll do something better once the mechanics are ironed out! ]

  • Ashley - for those of us that fail at maths - any chance of a feature like the following in construct? :)

    Click the image to go to the page - it's about box2D.

    I can't find any current examples in Construct2, not for lack of searching the manual, tutorials , forums and google.

  • Ey JohnnySix

    Some weeks ago I was wondering about something like that.

    I searched the web and after some time analyzing different mathematic formulas and lots of martian things (to me) like those, I change my view of the problem and get a solution. I can?t give it directly to you, but I can tell you (cuz mine is a very concrete example and is not adaptable for other projects) the way of getting it (very basic but it works).

    The base is use the "three rule" ("regla de tres" in spanish, I don?t know how to translate this :S).

    Knowing the factors you may know (power, speed, or whatever) make test depending on your game resolutions, and once the bullets hits a static point, use the "three rule" to get a custom formula that works in your concrete game resolution (sorry for my bad english).

    The idea is that: is the bullets hits a certain static (at first) target with your desired factors, extend it to make it works.

    You cant see what I got some weeks ago (taken directly from the devlog):

    <img src="http://egoitzosa.com/x/wildWest/2012_12_08_flechas.gif" border="0" />

  • Haha, thanks - will check it out.

    I started on the Wiki page, and then lost it when I got to the formulas at the bottom.

    en.wikipedia.org/wiki/Trajectories

    I need a derivative as I'm working backwards from the mouse x/y to then calculate the appropriate velocity and angle of launch to arrive at that spot.

    A Parabola would work if I turned off all friction, but it'd be less realistic.

    en.wikipedia.org/wiki/Parabola

    I'm thinking I'll just take the midpoint between the mouse x and the cannon for now and calculate a parabola for now, until I can get my head around the maths. Argh.

  • When I was looking at it, I saw that most of the people (when designing a parabola for a game) create a false bullet.

    A (future invisible) bullets that goes straight to the target, and the real bullets calculates the path to combining with it�s own speed, friction, ...

    I can�t help much more, sorry :/.

  • Yeah, that could work too - it's just as the game would get more complex, it'd need to have no collision with anything, and I think that's only possible by turning off collision with everything that is physics per item.

    I found this - which makes things a little easier to understand.

    yaldex.com/games-programming/0672323699_ch13lev1sec3.html

    <img src="http://www.yaldex.com/games-programming/FILES/13fig15.gif" border="0" />

  • It seems fairly linear - I guess just calculating a parabola would be enough from a quick test.

    Click image to try - this is just the gun from the game isolated.

  • Hi, any .capx for better understanding pls?

  • Here's the cannon :

    http://www.johnnysix.net/games/parab.capx

    <img src="smileys/smiley1.gif" border="0" align="middle">

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I'm a little unclear on what you are asking. Is it how to actually trace it, or how to derive the equation?

  • I'm having trouble deriving the equation for the target area.

    So for example, when you place the cursor over a target, the barrel would aim to get the shot at that point, compensating for gravity/drag.

    Or failing that, how I'd go about scaling a circle to roughly approximate it, given the known variables of starting velocity,angle and gravity.

    I guess the simplest way would be to do the invisible bullet thing, but with a lot of other physics things going on, I didn't want to slow it down too much.

  • JohnnySix, compensating for gravity is easy. Compensating for drag is another thing. I do not know the equations for that at all.

    If you removed drag, I could certainly help you with the parabola equation.

  • Here is an example that predicts the path of a projectile. It also calculates a speed/angle to shoot so that the projectile path passes over the mouse position. You could alternately just set the speed and angle.

    https://www.dropbox.com/s/9tftyryvn0pab ... .capx?dl=0

    This one has the math to take into account linear damping:

    https://www.dropbox.com/s/f5jsfbl3d1szj ... .capx?dl=0

  • Oh, wow R0J0, that's fantastic! Glad we have someone here who knows the iterative algorithms behind linear damping!

  • Ashley - for those of us that fail at maths - any chance of a feature like the following in construct? :)

    Click the image to go to the page - it's about box2D.

    I can't find any current examples in Construct2, not for lack of searching the manual, tutorials , forums and google.

    I tried running through that same tutorial just last week - At first I tried making a plugin that interacted with Box2D directly, but managed to confuse myself. Then I tried recreating it in Construct...but managed to confuse myself <img src="smileys/smiley9.gif" border="0" align="middle">

    Could something like this be done through C2/plugin?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)