# How do I Predict Movement?

Get help using Construct 2

### » Sun Mar 09, 2014 6:48 pm

Hello,

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

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,707

### » 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
96
S
34
G
33
Posts: 3,007
Reputation: 27,911

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

### » 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
95
S
34
G
128
Posts: 5,493
Reputation: 81,674

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

### » 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?
B
16
S
4
G
2
Posts: 233
Reputation: 2,560

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

### » Sun Mar 09, 2014 10:28 pm

oldX + cos(yourangle) * (30*10)= new x
oldY + sin(yourangle) * (30*10)= new y
B
173
S
50
G
194
Posts: 8,569
Reputation: 121,374

### » Sun Mar 09, 2014 10:45 pm

What newt said, I always forget something if I don't actually implement it.
B
95
S
34
G
128
Posts: 5,493
Reputation: 81,674

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

Next