Parabola/Tracjectory tracing with Physics / Box2D

0 favourites
From the Asset Store
Game for kids for tracing letters. A simple game for tracing letters.
  • R0J0hound - thanks so much - I wasn't expecting a working example, that's brilliant! <img src="smileys/smiley1.gif" border="0" align="middle">

    I did a quick experiment combining it with the Physics tank and it works amazingly. <img src="smileys/smiley32.gif" border="0" align="middle">

    Click image to play.

    It makes more sense to me now the way you presented it, thanks for taking the time to create the demo. <img src="smileys/smiley10.gif" border="0" align="middle">

    Arrow keys move the physics tank, recoil is calculated at a reduced amount based on the velocity of the ball.

  • R0J0hound that's fantastic! I've been wanting to do this for ages.

  • R0J0hound: That's...holy heck. I think I just spent the last month fiddling with a system that I can just replace with this. I'm both amazed and kicking myself at the same time. I don't know what to feel!

  • Sorry to double post, but I had a question for R0J0hound :

    I was wondering if there was a way to speed up the object that travels along the path?

    I'm only just getting used to physics so I may be way off here. I'm trying to set my object to have gravity 30 so that it travels up and down quite fast. The algorithm in your capx seems to take the mass of the object into account, but will always give it enough vx and vy to get to it's destination, therefore putting it at a constant speed regardless of the mass.

    For now I was able to just cobble together a solution where I multiply the vx and vy by 1.75 for gravity 30, which works out fine (the bullet travels much faster and follows the line nicely), but surely there is a better way of doing it? <img src="smileys/smiley1.gif" border="0" align="middle" />

    Is there another or better way to speed up the object as it travels along the path, be it by increasing the gravity or otherwise?

  • If you set the physics gravity to 30 then change the global variable ay to 50*30 or 1500.

  • If you set the physics gravity to 30 then change the global variable ay to 50*30 or 1500.

    Oh, 50! That fixes it. I figured out at one point that I probably should be multiplying ay, but I was doing 500 * gravity, not 50. That makes sense though - 500 I'm guessing is based on 50 * gravity(10), so setting it back to 50 and then multiplying it works. At the risk of badgering you too much, where does the number 50 come from? Why is that the base value?

    Thanks mate! You're like a mysterious super-hero of games coding.

  • 50 is just a conversion factor from box2d units/sec^2 to pixels/sec^2. I found it by measuring how far a physics object dropped and plugging it into this formula y=0.5*a*time^2 solved for a a=2*y/(time^2) which gave a value ~=500 or 50*physics.gravity.

  • Very cool, thanks mate!

  • Anyone else having a problem opening the .capx. I am getting an error stating the file was saved in version 115! Version 115 does not exist. I have the latest version from 12/21. Any help would be appreciated. Thanks.

  • It's a beta version - the latest is actually r117. :)

  • R0J0hound, thank you very much!

    I have some questions.

    1- Please can you explain me how can I change the speed? Beacuse the ball it's to slow.

    2- Is it possible add cursor/pointer/target at the end of trajectory line?

    eg.

    <img src="http://img703.imageshack.us/img703/3998/pointertargetcursor.jpg" border="0" />

    Thank you! :)

  • This is perfect and exactly what I was looking for!

    Although there's a consistency problem when I changed the posx from 0 to half of the window width. When I move the mouse in -x direction of posx the parabola is different than when it's in the equal opposite side of posx. Moving the mouse across the screen from left to right, the parabola height grows.

    I figured it had to do something with mouse.y-clamp(mouse.x, 100, 1000)) but I somehow end up screwing the path when attempting to modify.

    Have you a suggestion?

  • GamesDev

    1. You change the speed by adjusting the target angle. In the example ang is set to point a bit above the target, to make it go faster just have ang point a little lower. If ang points right at the target the speed will be fast enough to reach the target in one frame.

    2. You could just position a sprite to the mouse.

    bon4ire use this modified equation:

    angle(posx,posy,mouse.X,mouse.Y-clamp(abs(mouse.x-posx), 100,1000))

  • R0J0hound Thanks! It worked :D

    I tried to adopt for touch by replacing all mouse references to touch.

    The part to launch the ball with a mouse click down I changed to 'touch end' When I did that, the ball no longer launched.

    Here's an attached capx to look at.

    dl.dropbox.com/u/17062392/proj_path_phys_touch.capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • R0J0hound

    Thank you very much! :)

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