Parabola/Tracjectory tracing with Physics / Box2D

Get help using Construct 2

Post » Thu Sep 22, 2016 10:20 pm

@IJCT
Best I can tell from looking at the events is they have to be done in order, and triggers can be run at any time.

Basically the the three events are:
"every tick" which calculates the stating velocities
"the input check" which launches an actual physics object with the calculated velocities
"the loop" which takes the calculated velocities and simulates physics steps to find the path of the ball.

So if you want to launch a ball with a trigger such as a function you need to run the every tick event first somehow. Could be as simple as copying it.
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Tue Sep 27, 2016 10:51 am

R0J0hound wrote:@IJCT
Best I can tell from looking at the events is they have to be done in order, and triggers can be run at any time.

Basically the the three events are:
"every tick" which calculates the stating velocities
"the input check" which launches an actual physics object with the calculated velocities
"the loop" which takes the calculated velocities and simulates physics steps to find the path of the ball.

So if you want to launch a ball with a trigger such as a function you need to run the every tick event first somehow. Could be as simple as copying it.



thanks! i did figure out a way to do it, im doing an angry birds clone just for learning so thats why i was needing the help, what i did it was this:

Image

this can simulate a trigger input, so if everyone needs help doing this, they can just do that (the variable "resortera" means slingshot in spanish is just a condition for a state in my project so you can ignore it)

thanks a lot for the capx, it helped me a lot, i did some small modifications to it to have a more realistic angle and i may upload a demo so everyone can see the small tweaks i did ;)
Image
B
29
S
11
G
2
Posts: 260
Reputation: 5,017

Post » Sat Oct 01, 2016 3:51 pm

Hey @R0J0hound,

just discovered this thread when searching for an impact prediction for a bullet-behaviour-controlled object.

I tried to apply your calculations to my project, but that didn't quite work out, since my setup is a bit different compared to yours.
Can you help me with this? (Image of current setup further down)

I have the following scenario:
A projectile with the bullet behaviour gets shot from a specific angle (and a slightly elevated position) at a specific initial speed (400) and gets dragged down by the bullet's gravity (450).
So the thing is, I don't set the initial horizontal and vertical speed with the mouse, but with the bullet's initial speed.

I want to mark the impact point on the ground (at a specific y = 570) with a sprite.
So I tried to set the sprite's position to posx,570, after repeating the loop 11 times.
The sprite was somewhere near the impact point, but nowhere near the accuracy in your example.

My question to you is now:
To which number should I modify the loop count and do I even need a step value, since I don't need any trajectory displayed?

Thanks for any answer, here is my current setup:
Code: Select all
http://i.imgur.com/Nrrat3j.png?1
("Launcher" is slightly elevated)
(I don't expect you to deal with the mess of my capx)

(Btw, I took a look at the bullet launch in the debug view and figured that on launch, the bullet's vx0 is the set Bullet.Speed and vy0 is always 0, maybe that's an issue here..)
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
11
S
5
G
4
Posts: 273
Reputation: 3,521

Post » Tue Oct 04, 2016 7:32 pm

@randomly

If you just want to mark the point it hits the ground then you can either just set speed to the bullet's speed or if the ground is flat you can just calculate the impact x directly by taking these two equations and solve for x:

y = initial_y + initial_y_velocity*time - 0.5*gravity*time^2
x = initial_x + initial_x_velocity*time

which would be:
x= initial_x + 2*initial_x_velocity*initial_y_velocity/gravity
if the bullet was launched from ground level
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Tue Oct 04, 2016 7:45 pm

@R0J0hound

Thanks for the answer.
Actually, the launching position is higher than the ground.
I tried applying your original formula to my project, exchanging the speed to the bullet's speed and changing all other stuff to my equivalent objects (which didn't work).

If I now want to use the solved two equations for an elevated launch position, what shall I modify?
And for the initial y and x velocity, should I just take the velocities from the debug mode (being x=400 and y=0 on launch)? Because the Bullets behaviour obviously doesn't allow me to set x and y velocity seperately..

[EDIT]
I figured I maybe have to set the initial y velocity to launching_speed*sin(launching_angle)
and the initial x velocity to launching_speed*cos(launching_angle).
Since my launcher's angle is somehow always set as 360-actual_angle, I also figured I'd change the launching_angle to abs(360-launching_angle). Using this, my current setup looks like this: http://i.imgur.com/TK4pTAQ.png

It kinda works, but the accuracy is always ± ca. 100 pixel (horizontally) which is not exactly what I'd consider accurate...any idea what I did wrong? Is it the elevated launching position?
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
11
S
5
G
4
Posts: 273
Reputation: 3,521

Post » Tue Oct 04, 2016 9:25 pm

thank you for share the capx file!
B
45
S
9
G
10
Posts: 194
Reputation: 8,165

Post » Thu Oct 06, 2016 6:04 am

@randomly
I'm unable to see what's amiss. I don't have access to C2 and what you want to do is different enough it's probably easier to start from scratch.

In regard to the alternate idea in my last post to calculate the impact point exactly: the process is to use algebra to manipulate the first equation into the form ax^2+bx+c=0 and use the quadratic formula to solve for x. Well except it will be time in the equation. Anyways we can disregard that one for now.

You said the bullet behavior doesn't give X and y velocty. While this is true, you still can convert it over:
Vx = speed*cos(angleofmotion)
Vy = speed*sin(angleofmotion)

You can also convert it the other way
Angleofmotion = angle(0,0,vx,vy)
Speed = distance(0,0,vx,vy)

The most complicated bit of the original example are these three actions:
add vx*dt to X
Add gravity*dt to vy
Add vy*dt to y

Those change the velocity and position to what they would be after dt seconds. You can replace dt with any duration you like. Next put those actions under a repeat condition and it is done multiple times. So say you repeat 10 times and use 0.1 instead of dt, it'll calculate where the position will be after 10*0.1 or 1second.

I did skip a step though. Before the repeat you need to set X,y,vx and vy to what the bullet is currently. As a sub-event of the repeat event you can check so see if y is below the ground level, and then stop the loop and place the marker.

Alternatively you could position a second Sprite at the bullet and move that instead of using Xy variables.
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Thu Oct 06, 2016 2:05 pm

@R0J0hound

Thanks so much for answer!
This works perfectly for predicting the impact while flying!

The thing is, I want to predict the impact before launching. That means, since the initial speed and gravity are known, I could predict the impact x coordinate, right?

I just need the right formula for that...
As I said, your formula works perfectly for predicting the impact when the bullet is flying.
I don't think though, that I can predict the impact point before the actual launch.

The reason might be that the angle of motion can't be predicted in the formula for the process of flying.


Maybe I'm really not grasping something here, or my idea isn't even possible.

Thanks for your continuous dedication for my problem, I hope I'm clear enough about what my goal is here.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
11
S
5
G
4
Posts: 273
Reputation: 3,521

Post » Sun Oct 09, 2016 7:10 pm

@randomly Predicting maximum height & range for a bullet.

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

Ground is drag & drop
Right mouse = shoot
Mouse wheel = angle
B
17
S
10
G
17
Posts: 1,405
Reputation: 12,118

Post » Mon Oct 10, 2016 12:30 pm

@99Instances2Go

You are amazing, thank you so much!
I applied your formula(e) to my project and it worked perfectly!
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
11
S
5
G
4
Posts: 273
Reputation: 3,521

Previous

Return to How do I....?

Who is online

Users browsing this forum: Televangelist and 22 guests