# Steering behaviors math

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

## 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.

##### 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 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 from the book Vector2D SteeringBehaviors::Seek(Vector2D TargetPos) { Vector2D DesiredVelocity= Vec2DNormalize(TarfetPos - m_pVehicle->Pos())* m _pVehicle->MaxSpeed(); return (DesiredVelocity - m_pVehicle->Velocity()); } 

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 on other sites

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.

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 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 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.