Are you assuming the rate of acceleration is constant? If so,
A = (v(T) - v0) / T = (V(T) - v0) / T = - v0 / T
where T is the time it takes for v0 (initial velocity) to reduce to v(T) (= 0, final velocity), and A is the constant rate of acceleration (which is negative if v0 > 0, hence is really deceleration).
If the rate of acceleration is constant, then the position of the object is given by a quadratic, like
p(t) = p0 + v0 * t + 0.5 A t^2
You said you know the distance, D, which must equal p(T) - p0, so
D = v0 * T + 0.5 * A T^2
which gives
T = (-v0 + sqrt(v0^2 + 2 * A * D) ) / A
substituting into the first equation and simplifying yields
@GarthSmith
Those equations seem to be exactly what I needed!
Except when I actually plugged them into my code, the acceleration it produced was WAY underpowered; it felt like something between 30 -100 times too low.
In the start function I have:
acceleration = Mathf.Abs((maxSpeed * -1) / decelDist / 2);
The design is that the object is supposed to proceed at full speed until it it called to turn the other direction. Then it executes this code each frame, causing it to accelerate in the opposite direction. (Once it hits full speed I run different code.) The distance I give it (decelDist) is the distance I want it to travel before it reaches its apex and starts moving in the opposite direction.
It functions correctly; it does move a specific distance before reaching that apex, and I can adjust that distance. It’s just that distance is a good 50 times or more what I thought I was setting it to.
Took a simpler route (than I used the first time, which must’ve been riddled with errors) to solving for A and got the same thing as Garth. That’s certainly the appropriate formula.