[SOLVED] Physics object Impulse, Parabolic Arcs, and Pre-set targets?

0 favourites
  • 11 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I have a physics object that I want to launch towards a preset/target in an arc. It should hit the target in its downward path, preferably with the peak of the parabola at the midpoint of the origin and target. I also have a max and min launch angle. How can I calculate the impulse needed to make that happen?

  • Perhaps this can help you, although it's not directly made with the physics behavior in mind. The math should probably be roughly the same I think.

    howtoconstructdemos.com/trajectory-calculation-two-methods

  • Thank you for this, although I'm still lost. Pretty new to the physics behavior, rarely use it. I tried to imitate the first example (Calculating trajectory speed using gravity and time of flight as constants), but I can't get it to work. I used set velocity for vX, vY. Am I doing it wrong? There's barely any movement.

  • Hmm now that I think about it, this is probably a bit more complicated. The physics plugin uses more variables that will affect the trajectory. Like mass/density and dampening. Since construct uses box2D under the hood I searched if there's something on that and found this answer but the math is beyond me and I don't have time right now to read into it.

    stackoverflow.com/questions/20208642/draw-dynamic-projectile-curve-in-box2d

    Maybe R0J0hound can help here.

  • Thanks, I'll try to look into this, but if anybody else has ideas, please let me know. I'll mark the thread solved and post the solution here if I ever figure it out.

  • That example should have what you need. I mean you can calculate it yourself too if you want. The equations for projectile motion is this. X0,y0 is the start position, x1,y1 is the end position, vx,vy is the launch velocity, a is the gravity, and t is the flight time. You can then use algebra to solve for the unknowns.

    X1=X0+vx*t

    Y1=Y0+vy*t+0.5*a*t*t

    But anyways. With the physics behavior it should still work. Just set the velocity on launch and you won’t have to worry about mass. With damping at 0 it should be flawless, but damping in general would throw it off. I don’t know if anyone worked out how damping is done to work with that.

    Maybe you’re making a typo or something when adapting that example to your events.

  • Hmm I just can't quite get it to work

    wackytoaster.at/parachute/notquitephysicstargeting.c3p

    I've tried various versions of the equation but it never quite works for all distances. I'm not sure what I'm missing...

  • Three changes and it will work.

    1. Make the gravity local variable static. Since it’s in a group it’s just a local and gets reset to 0 every tick as is.

    2. Make the gravity variable x50 times what you use for the physics behavior gravity. Why? With box2d the standard use is to scale the physics units from the pixel units. That shouldn’t affect us but when they made the behavior they didn’t make sure the units were all uniformly converted. So x50 comes up a lot.

    3. Use (vx,-vy) when you set the velocity. A negative was forgotten when solving the formula.

    And as a bonus:

    4. Use (vx,-vy-gravity/60/2) when you set the velocity. Without that the path will be slightly lower than the target. Why? There is something off when things update in the behavior. It applies gravity once. However I think this mainly happens when objects with physics are just created. I honestly forget, but in the chipmunk behavior I made a point to avoid that quirk.

    Cheers

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Been trying it, no luck. I also tried WackyToaster's test and applied all changes you mentioned, but it's still not working?

    Also, in the bonus, is the 60 in there frames? Does that mean I can't play around with timescale when using physics?

  • I just tried it and r0j0 is correct. I can't update the project on my server right now but if you replicate the screenshot it will work perfectly. Also it will work fine with timescales :) Thanks r0j0

  • Oh, it works now! I had the physics world gravity set to the variable gravity, so it messed things up. Thank you! R0J0hound WackyToaster. It also works perfect even when I change the timescale!

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