Advertisement

Constant acceleration: Point out why I am an idiot

Started by September 16, 2012 10:57 AM
1 comment, last by Pasanova 12 years, 5 months ago
Sorry to reference such an old thread but http://www.gamedev.n...ering-behavior/
refers precisely to the thing I am having trouble understanding!

In

//calculate the speed required to reach the target given the desired
//deceleration
double speed = dist / ((double)deceleration * DecelerationTweaker);

How does this calculate the speed? I just cannot understand it, besides doesn't
x/a have the dimensions of time squared?
I think it should be completely different, I am obviously missing something
u-Initial (current) velocity required (what we want to calculate above)
v - Final velocity (in this case zero)
x - Distance to target "dist" in the above?
a - The acceleration, in the above a = -deceleration * DecelerationTweaker?
Constant acceleration equation:
v^2 = u^2 + 2ax
therefore
u = sqrt(2*deceleration * DecelerationTweaker*x)
Can anybody point out the error?
It looks like he defined "deceleration" not as an acceleration (m/s^2) but as a unit of time (s), which then agrees dimensionally as v = d/t. His code doesn't actually seem to be considering agent acceleration. All it does is measure the distance from the agent to the target, use v = d/t to obtain the velocity needed to traverse the distance in the required time assuming zero acceleration, and orients the velocity using the direction vector from the agent to the target. It also makes sure the speed is bounded to the maximum speed of the agent.

So as far as I can tell, his code assumes the agent is never accelerating, which makes for some pretty basic steering, not what you are looking for.

By the way, you can ignore decelerationTweaker in your code, as for some reason DrunkenBrit uses it to extend his enum to floating-point precision, which has nothing to do with the physics at all (looks like a code crutch).

You are not an idiot.

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

Advertisement
Thanks Bacterius!
I have just reread that section and you are exactly right! Thank you so much!
It makes a lot more sense to me now :) It is a very good book in general
even if the variable names are very misleading here!

This topic is closed to new replies.

Advertisement