# How do I Calculate this position X

Get help using Construct 2

### » Sat Apr 21, 2018 8:05 pm

Hi, I have a sprite with platform behavior.
Maximum speed 60
Deceleration 240

I need to figure in which X coordinate will brake the sprite completely when I do not press any key.

I mean, I need to calculate in advance the X that the sprite will have when it stops completely.

What calculation do I have to do with the maximum speed and braking speed?

The acceleration is instantaneous (10000) so I do not take it into account. But if you know the calculation also with the acceleration, then I could alter this and use your calculation to help me.

B
36
S
15
G
22
Posts: 959
Reputation: 15,228

### » Sat Apr 21, 2018 8:37 pm

Stopping distance would be = (speed^2)/(2*deceleration)
B
101
S
39
G
134
Posts: 5,591
Reputation: 85,520

### » Sat Apr 21, 2018 8:42 pm

Here's a cheat.

The deceleration is always constant. So assuming your actual moving speed is always the same (like you said), the braking distance is constant, too. You can actually measure the braking distance by capturing the X position of the Sprite when the key is released, and then capturing the X position again when the Sprite stops.

EDIT: whoops, looks like R0J0hound's got the legit answer.
B
57
S
20
G
1
Posts: 124
Reputation: 4,428

### » Sun Apr 22, 2018 8:17 am

Thanks guys, the formula of R0J0hound works perfect.
But ... why is it multiplied by 2 and not by another number?
B
36
S
15
G
22
Posts: 959
Reputation: 15,228

### » Sun Apr 22, 2018 9:03 am

@The Mnk
The Formula for braking distance is Sb=V²/2*a with V for the velocity and a for the deceleration

The velocity over braking time is:
v(t) = V - a*t
The distance over time:
s(t) =V*t-0.5*a*t²

Now you have to know how long the braking takes :
v(t)=0
=> 0 = V-a*t
<=> t = V/a

with s(t) =V*t-0.5*a*t² and t=V/a
=> S= V*V/a-0.5*a*V²/a² = V²/2*a

(speed^2)/(2*deceleration)
B
27
S
3
G
1
Posts: 500
Reputation: 2,355