Sign in to follow this  
JoaquinBelloDecurnex

Steering behaviors math

Recommended Posts

[color=#1C2837][size=2]I'm reading "Programming game AI by Example" and i reach the part where it talks about how to create autonomously moving agents.
To calculate the steering force the book propose to calculate the desired velocity and then subtract the current velocity. The thing is i cant understand how the subtraction of 2 velocities can be transform into a force.
For me the subtraction of 2 velocities is equal to delta V and also equal to acceleration*delta time.

can somebody explain me why the subtraction of 2 velocities its equal to a force.[/size][/color]

Share this post


Link to post
Share on other sites
Without bothering to reach up and grab my copy off the shelf, I think the problem is simpler than you are making it.

If I want to go 10 and I'm going 6, I need to go 4 more.

If I am now going 8, I need to go 2 more.

If I am now going 9, I need to go 1 more.

The result of this is that the closer you are to your desired speed, the less force you want to apply. This makes for a very gentle arrival at your desired speed.

Think of accelerating your car... as you get closer to your intended speed, you let off the accelerator so as to creep up on the target velocity. The same for turning... as you get close to your desired direction, you slow your rate of turn so as to gradually approach that direction.

Share this post


Link to post
Share on other sites
thanks for you answer.Maybe the force apply to the agent its just some approximation to the real force needed.
I have the same problem in all the behaviours, for example the simplest seek
[code]
Code from the book
Vector2D SteeringBehaviors::Seek(Vector2D TargetPos)
{
Vector2D DesiredVelocity= Vec2DNormalize(TarfetPos - m_pVehicle->Pos())* m _pVehicle->MaxSpeed();

return (DesiredVelocity - m_pVehicle->Velocity());
} [/code]


The result of the steering behaviors its divided by the mass to obtain the acceleration, so the result of seek its treated like a force.

Share this post


Link to post
Share on other sites
[quote name='juako' timestamp='1306102669' post='4814366']
The result of the steering behaviors its divided by the mass to obtain the acceleration, so the result of seek its treated like a force.
[/quote]

The behavior is described as "generate a force proportional to the difference between where you are and where you want to be." The constant of proportionality seems to be 1, but I don't think that's particularly important.

Share this post


Link to post
Share on other sites
I think i got confused by the fact that maxVelocity and the maximum force you can apply to the agent are close related.
i got confused by this line in page 91 chapter 3
"The steering force returned by this method is the force required, which when added to the agent´s current velocity vector gives the desired velocity"

Its true that statement if the mass is equal to 1, you get the desired velocity otherwise you get something proportional.

Im really sorry for being so persistent on the subject , but my final project at the university use some AI and i want to understand why its done and not just do it.

Share this post


Link to post
Share on other sites
I got confused at the very same place !

I realized that later in the book, the author is using a constant frame rate. So that could explain the fact that for him, a delta V (difference of speed vectors) is proportional to the acceleration required.

But I still disagree with the division by the mass !

I'm about to implement something similar, but I will male the following adjustments :
- As the mass of the various agents is constant (at least in my case), once we know the mass and the max force the agent can apply, it's trivial to find the max acceleration he can achieve. (Max accel = Max Force / mass).
- The steering behavior like Seek will return a desired acceleration vector. The Update method of the agent will then clamp it to the max acceleration the agent can get.
- Once clamped, the desired acceleration is multiplied by the time since the last frame (in my case it's not a constant), and this is added to the actual speed vector. The speed vector gets clamped as well (because there's a max speed the agent can achieve), and this get multiplied by the time since last frame and added to the position vector.

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