# Parabola/Tracjectory tracing with Physics / Box2D

Get help using Construct 2

### » Tue Jan 15, 2013 6:26 pm

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.
B
27
S
9
G
5
Posts: 492
Reputation: 11,958

### » Tue Jan 15, 2013 10:15 pm

@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.
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,729

### » Wed Jan 16, 2013 7:46 pm

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
Last edited by R0J0hound on Tue Mar 21, 2017 9:01 am, edited 1 time in total.
B
94
S
33
G
124
Posts: 5,458
Reputation: 79,479

### » Wed Jan 16, 2013 7:57 pm

Oh, wow R0J0, that's fantastic! Glad we have someone here who knows the iterative algorithms behind linear damping!
B
92
S
31
G
24
Posts: 3,191
Reputation: 32,729

### » Thu Jan 17, 2013 2:34 am

[QUOTE=JohnnySix] @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.[/QUOTE]

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

Could something like this be done through C2/plugin?
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

### » Fri Jan 18, 2013 10:21 pm

@R0J0Hound - thanks so much - I wasn't expecting a working example, that's brilliant!

I did a quick experiment combining it with the Physics tank and it works amazingly.

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.

Arrow keys move the physics tank, recoil is calculated at a reduced amount based on the velocity of the ball. JohnnySix2013-01-18 22:22:41
B
27
S
9
G
5
Posts: 492
Reputation: 11,958

### » Sat Jan 19, 2013 12:10 pm

@R0J0hound that's fantastic! I've been wanting to do this for ages.
Moderator
B
72
S
14
G
11
Posts: 900
Reputation: 11,945

### » Sat Jan 19, 2013 7:51 pm

@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!
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

### » Sun Jan 20, 2013 3:34 am

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?

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?boolean2013-01-20 03:35:01
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

### » Sun Jan 20, 2013 4:00 pm

If you set the physics gravity to 30 then change the global variable ay to 50*30 or 1500.
B
94
S
33
G
124
Posts: 5,458
Reputation: 79,479

PreviousNext