How do I Predict Movement?

Get help using Construct 2

Post » Sun Mar 09, 2014 6:48 pm

Hello,

I have this diagram and I'm trying to work out the solution.

Image

I have a ship, traveling at 10 pixels per second with an angle of 315 degrees (North East)

His position:
X: 5000
Y: 528

How do I calculate where he'll be in 30 or so seconds?

Keep in mind we're in C2 and he's about to hit 0y and go into the negative.
B
34
S
10
G
5
Posts: 165
Reputation: 6,687

Post » Sun Mar 09, 2014 6:57 pm

The easiest way would be to place another object at its location then use the move at angle action, and have it move 10*NumberOfSeconds at 315 degrees. Keep in mind the location might not be exact depending on the fluctuations of dt if you're using it for physics.
Moderator
B
94
S
33
G
33
Posts: 3,006
Reputation: 27,744

Post » Sun Mar 09, 2014 8:47 pm

It would need a mathematical solution. The server needs to calculate this in the end.

We have the speed, it's starting point, we need a way to figure out it's ending point 30 or so seconds later.
B
34
S
10
G
5
Posts: 165
Reputation: 6,687

Post » Sun Mar 09, 2014 9:54 pm

Basically this:

newX = oldX + 10*cos(angle)
newY = oldY + 10*sin(angle)

But depending on the programming language you may need to convert the angle from degrees to radians.
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

Post » Sun Mar 09, 2014 10:06 pm

It's a start, but where does the 30 seconds fit in? We're using c2 for this example really.

Where will the dot be 30 or so seconds later?
B
34
S
10
G
5
Posts: 165
Reputation: 6,687

Post » Sun Mar 09, 2014 10:10 pm

I'd like to know if this is going to be school assignment, commercial product or hobby project?
Need help? Upload .capx file with your question.
B
16
S
4
G
2
Posts: 233
Reputation: 2,560

Post » Sun Mar 09, 2014 10:13 pm

I've got:
NewX = OldX + (30 * 10)
NewY = OldY - (30 * 10)

But this would only work if the dot is heading 315 degrees. I'll need to put more thought into what I'm trying to do.
B
34
S
10
G
5
Posts: 165
Reputation: 6,687

Post » Sun Mar 09, 2014 10:28 pm

oldX + cos(yourangle) * (30*10)= new x
oldY + sin(yourangle) * (30*10)= new y
Image ImageImage
B
168
S
50
G
163
Posts: 8,224
Reputation: 105,067

Post » Sun Mar 09, 2014 10:45 pm

What newt said, I always forget something if I don't actually implement it.
B
91
S
31
G
103
Posts: 5,235
Reputation: 67,756

Post » Sun Mar 09, 2014 11:10 pm

newt wrote:oldX + cos(yourangle) * (30*10)= new x
oldY + sin(yourangle) * (30*10)= new y


Cool, will this work if we change the heading from 315 degrees to 90?
Last edited by Taurian on Sun Mar 09, 2014 11:15 pm, edited 1 time in total.
B
34
S
10
G
5
Posts: 165
Reputation: 6,687

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 11 guests