# Bullet end point

Get help using Construct 2

### » 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
B
178
S
50
G
206
Posts: 8,686
Reputation: 127,715

### » 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.
B
255
S
65
G
34
Posts: 907
Reputation: 41,611

### » 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
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:
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

### » 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
100
S
38
G
134
Posts: 5,556
Reputation: 85,325

### » Tue Dec 03, 2013 11:29 pm

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

### » 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

### » 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!
B
178
S
50
G
206
Posts: 8,686
Reputation: 127,715

### Who is online

Users browsing this forum: Ishify and 5 guests