# Parabola/Tracjectory tracing with Physics / Box2D

Get help using Construct 2

### » Sun Jan 20, 2013 6:26 pm

[QUOTE=R0J0hound] If you set the physics gravity to 30 then change the global variable ay to 50*30 or 1500.[/QUOTE]

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

### » Sun Jan 20, 2013 8:12 pm

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.
B
98
S
36
G
131
Posts: 5,521
Reputation: 83,505

### » Sun Jan 20, 2013 11:28 pm

Very cool, thanks mate!
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

### » Wed Feb 06, 2013 12:15 am

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.
B
10
S
2
G
3
Posts: 7
Reputation: 2,590

### » Wed Feb 06, 2013 12:04 pm

It's a beta version - the latest is actually r117. :)
B
27
S
9
G
5
Posts: 495
Reputation: 11,964

### » Fri Mar 01, 2013 3:14 pm

@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.

Thank you! :)

B
5
S
1
Posts: 12
Reputation: 556

### » Sat Mar 30, 2013 2:00 pm

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?
bon4ire2013-03-30 14:03:31
B
31
S
6
G
4
Posts: 160
Reputation: 6,003

### » Sat Mar 30, 2013 6:33 pm

@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))
B
98
S
36
G
131
Posts: 5,521
Reputation: 83,505

### » Sat Mar 30, 2013 10:12 pm

@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.

https://dl.dropbox.com/u/17062392/proj_path_phys_touch.capx
B
31
S
6
G
4
Posts: 160
Reputation: 6,003

### » Sun Mar 31, 2013 12:09 pm

@R0J0hound
Thank you very much! :)
B
5
S
1
Posts: 12
Reputation: 556

PreviousNext