1
\$\begingroup\$

I have a top down 2d game that uses a physics engine (Farseer).

I'm using the standard steering behaviors to make the AI move around but I'm not sure the correct way to take the so called "steering force" calculated by the steering behavior and apply it to the physics bodies.

For example:

The steering behavior SEEK returns

return desiredVelocity - currentVelocity;

So it is returning a difference of two velocities (in meters per second).

I need to convert this into the force (in Newtons) that I need to apply to my physics body, taking into account its mass and acceleration etc.

I know it should be simply but I'm getting confused! :)

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Your bodies have a current 2d velocity : vcx, vcy. You desire a new velocity: vnx, vny. Correct? Now force translates into acceleration/mass (and velocity indirectly).

vnx - vcx = fx/m * t;
fx = m*(vnx - vcx)/t

So you need to know the duration of time force will be applied. Lets say a frame? Calculate the delta time of the frame.

Do the same with axis y.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks Arthur, I'll give this a go! Looks good to me, just haven't done any physics in a while. What has me very confused is that all the popular steering libraries I've seen, take the (desiredVelocity - currentVelocity) and use it like its actually a force, not a change in velocity! They use it in F = ma as the F value. I don't get it! \$\endgroup\$
    – TerryB
    Commented Mar 21, 2014 at 0:03
  • \$\begingroup\$ I don't think they use it as F. They probably use it to calculate a, it is very possible you'd want to keep the a bound in order to make changes in velocity appear smooth. If you use any a or simply replace the current velocity with the desired velocity, the movement will appear very rigid at times. \$\endgroup\$
    – AturSams
    Commented Mar 21, 2014 at 10:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .