# How to calculate acceleration distance(frictionless, massless)

Object A is moving via. 2D rigidbody by velocity V and in script is defined breaking power P. Every frame of breaking (P * Time.deltaTime) is subtracted from velocity V (in other words, ignoring mass). How i can calculate distance D required to slow down to target velocity tV ?

I'm not actually using force/power but i setting velocity directly with this line of code :

Vector3 dir = transform.TransformDirection(Vector3.up);
ship.rb.velocity = Vector2.MoveTowards(ship.rb.velocity, (dir * maximalSpeed) * ship.massModifier, speedGain / ship.massModifier);
(Don't worry about ship.massModifier, Basically heavier ship hulls are slower)

I'm self-learning Indie developer and i need this for AI to my game. Enemy in space ship have nothing like space-breaks so only way how to slow down is to turn ship by 180 degrees and thrust forward in counter-direction.I need to know this to calculate distance from target required to slow down and prevent possible collision with target.

## 1 Answer

Use the formula

$$t = \frac{v_0}{a}$$

$$s = v_0 \cdot t + \frac{at^2}{2}$$

where $v_0$ is the starting velocity, $a$ is the acceleration/deceleration and $s$ is the distance

• "where v0 is the starting velocity, a is the acceleration/deceleration and s is the distance" And what about target velocity ? @Bálint – Jacob Feb 7 '18 at 16:28
• @Garrom in that case use (v0/v1)/a when calculating t, where v1 is the end speed – Bálint Feb 7 '18 at 16:33
• So i must use 't= (v0/v1)/a' instead 't = v0/a' , right ? And one more thing, "t" is time what whole breaking/accelerating takes , right? – Jacob Feb 7 '18 at 16:39
• @Garrom Yeah, that's it – Bálint Feb 7 '18 at 16:42
• Just one last thing.I know this is stupid question but I was in special class and teacher refused to teach me stuff like this no matter of level of my intellect. "at" means a+t or a*t ?I know this is very basic knowledge but my math teacher was a jerk... – Jacob Feb 8 '18 at 12:58