Sign in to follow this  
Pasanova

Constant acceleration: Point out why I am an idiot

Recommended Posts

Sorry to reference such an old thread but [url="http://www.gamedev.net/topic/548538-arrival-steering-behavior/"]http://www.gamedev.n...ering-behavior/[/url]
refers precisely to the thing I am having trouble understanding!

In [quote name='DrunkenBrit' timestamp='1254071867' post='4533025']
//calculate the speed required to reach the target given the desired
//deceleration
double speed = dist / ((double)deceleration * DecelerationTweaker);
[/quote]
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this