ApplyForce(Vector2 force, Vector2 point) Issues

Feb 20, 2010 at 10:08 AM
Edited Feb 20, 2010 at 10:09 AM

It seems like ApplyForce(Vector2 force, Vector2 point) is not working quite right.


I noticed this in the ApplyForce test.  The ship did not seem to be behaving as I would have expected given the ApplyForce parameters being used.


Vector2 f = _body.GetWorldVector(new Vector2(0.0f, -200.0f));
Vector2 p = _body.GetWorldPoint(new Vector2(0.0f, 2f));
_body.ApplyForce(f, p);


As a test, I modified this to apply the force at what should be the center of mass:


Vector2 f = _body.GetWorldVector(new Vector2(0.0f, -200.0f));
Vector2 p = _body.GetWorldPoint(new Vector2(0.0f, 0.0f));
_body.ApplyForce(f, p);

I would expect this would NOT cause any torque when pressing just the 'W' key.  But it does.  Once the ship hits the blocks and is no longer aligned with the Y-axis, it appears the force is no longer applied correctly and the ship becomes uncontrollable.

Is this a bug or am I missing something?



Feb 20, 2010 at 6:53 PM

I don't think this is a bug, what are you missing is the fact that the ship is made up of 2 shapes with different densities.

This means applying a force at the center of the ship will result in torque moving in the direction of the heavier piece (the one on the left side).

If you make sure both pieces have the same density it should move more like a traditional "asteroids" ship.

Feb 21, 2010 at 2:45 AM

Ahh, ok. I did miss the difference in densities.