This project has moved and is read-only. For the latest updates, please go here.

ApplyForce(ref f) not applying force to center of mass?

Nov 23, 2013 at 4:45 PM
I am using version 3.5 and this came about through noticing some strange behavior with GravityController using a body which has an offset center of mass. What happens is when "dangled", the body swings like a pendulum against the GravityController gravity point.

The GravityController applies forces on bodies using:
worldBody.ApplyForce(ref f);

Body.ApplyForce(ref float) is commented as "Applies a force at the center of mass."

It calls Body.ApplyForce(ref Vector2 force, ref Vector2 point) which is commented "Apply a force at a world point. If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity."

So I guess that Body.ApplyForce(ref force) is supposed to be passing in the world center of mass of the body to Body.ApplyForce(ref force, Vector2 point), which in turn will not generate a torque. But I am seeing it is generating a torque - but only when the body has an off-center center of mass (center of mass != body position).

I notice Body.ApplyForce(ref Vector2 force) calls:
ApplyForce(ref force, ref _xf.p);

I don't have a clue about the physics, but is _xf.p the center of mass? I notice that Body.WorldCenter returns _sweep.C not _xf.p for example and _sweep.C seems to be used elsewhere for center of mass.

To test I changed the call to
ApplyForce(ref force, ref _sweep.C);

and now no torque is applied, the GravityController behaves correctly (no torque) and everything else seems to work okay.