Bullet end point

Get help using Construct 2

Post » Tue Dec 03, 2013 5:18 pm

Just thought Id check here to see if any one had the formula to project where a turning bullet will wind up, after a given time, speed, rate of turn, and angle.

No cap needed, but wont be turned down of course.

Thanks
Image ImageImage
B
172
S
50
G
183
Posts: 8,439
Reputation: 115,597

Post » Tue Dec 03, 2013 5:39 pm

This is not the answer, (consider it a bump) but on a quick search I found this Parabola calculator showing kicking a ball that may be good at math, but a bit of a fail on ball kick.

Click "kick it" and see how math simulates life. "Except for how the air affects it."
It made me laugh out loud.
http://www.mathsisfun.com/geometry/parabola.htmlParadox2013-12-03 17:40:19
B
242
S
63
G
33
Posts: 903
Reputation: 40,756

Post » Tue Dec 03, 2013 8:07 pm

per tick the movement will be:

x: cos(startangle+turnrate*elapsed_time)*bulletspeed*dt
y: sin(startangle+turnrate*elapsed_time)*bulletspeed*dt

turnrate = turnrate per time

Since dt is not constant, you can't solve the integral up front. Nonetheless you can approximate it, if you can assume your game to run at a stable fps, because then you can basically see this function as

cos(A+B*x)*C where the integral would be sin(A+B*x)*C/B
x is your time
C = the constant dt you expect (60 fps -> 1/60) multiplied by the bullet speed
A = starting angle
B = angle turned per second
the result would be the x-position in relation to the starting point of your bullet


Maybe it is possible to eliminate the dt by adjusting the turnrates dynamically along the process, so that the function will look like this:

cos(startangle+turnrate*dt*60*elapsed_time)*bulletspeed*dt

I am not sure how the turn angle expression should look for that, though, maybe a simple

every tick: set angle to angle+turnrate*dt will do the trick.

edit2: yeah I guess this will suffice and makes the end point not reliant on fps:
http://s000.tinyupload.com/index.php?file_id=34186910167149130523mindfaQ2013-12-03 20:25:41
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Tue Dec 03, 2013 11:07 pm

Hi, here's my 2c.
Since the motion is just along a circle we can calculate the center and radius of that circle and build a nice exact formula to find where the object will be. You do have to account for the case where the rate of turning 0, because motion will be in a straight line and my formula will fail.

Here's a capx:
[https://dl.dropboxusercontent.com/u/5426011/examples20/position_perdict.capx[/url]
The last 3 events are the formulas. The rest is just gui nonsense.
B
94
S
33
G
118
Posts: 5,393
Reputation: 75,847

Post » Tue Dec 03, 2013 11:29 pm

@R0J0hound is considered as math genius. :)
B
99
S
35
G
29
Posts: 3,139
Reputation: 28,421

Post » Wed Dec 04, 2013 1:04 am

You'll need the integral once you change the amplitude, turnrate or speed over time, though.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

Post » Wed Dec 04, 2013 1:13 am

Alright I think I can figure something out now.
I think what I'll try is a drag and drop kind of thing where the end point will be a point on a circle, and the center is the bullet origin.

Thanks guys!
Image ImageImage
B
172
S
50
G
183
Posts: 8,439
Reputation: 115,597


Return to How do I....?

Who is online

Users browsing this forum: dop2000, LunaticCat, plinkie and 6 guests