Jump to content
  • Advertisement
Sign in to follow this  
Pasanova

Constant acceleration: Point out why I am an idiot

This topic is 2103 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!