• Create Account

Constant acceleration: Point out why I am an idiot

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

#1Pasanova  Members

119
Like
0Likes
Like

Posted 16 September 2012 - 04:57 AM

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?

#2Bacterius  Members

13100
Like
2Likes
Like

Posted 16 September 2012 - 07:55 AM

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.

Edited by Bacterius, 16 September 2012 - 08:18 AM.

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

#3Pasanova  Members

119
Like
2Likes
Like

Posted 16 September 2012 - 08:52 AM

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!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.