ClearForce();

Topics: User Forum
Oct 29, 2007 at 2:09 AM
Edited Oct 29, 2007 at 2:17 AM
Edit: I figured this out, just needed to set LinearVelocity to Vector2.Zero, I completely missed that property. But now im confused as to what ClearForce() accomplishes. can anyone explain the differences, because it seems to me that if i set linear velocity to zero then the force is canceled too because the arrow was not effected by the previous force even when i dont do ClearForce()

I am fooling around with Farseer making a little guy shoot arrows at the mouse direction. I do
arrow.ApplyForce(Vector2.Multiply(direction, 300));

then when You click again i want it to clear the forces, pretty much create a new arrow and fire it at the new direction with only that force.

what it seems like is happening is the forces are still present even though the arrow's position gets reset. If i fire straight up the arrow goes at (0,-300) velocity for example. but then when i fire down it is (0,0) instead of (0,300).

I have arrow.ClearForce(); right before i apply the new force. i looked at the body.cs code and it looks like ClearForce(); should just set the forces for the body to (0,0). which i believe it does. I guess i need to ask if there is a way to set the speed/velocity to (0,0)?

thank you.
Oct 29, 2007 at 3:08 AM
Edited Oct 29, 2007 at 5:39 PM
I believe that when you apply a force to launch the arrow, that force is no longer present in the next update of the simulator unless it is reapplied. (I could be wrong, maybe I'm thinking more along the lines of impulse) If I'm right, then ClearForce() is just used to clear any forces that may be applied in the next update.

From your description, I tried to replicate your situation. I was getting the same problem, until I realized that I was calculating the direction vector before I moved the object back to its starting location. That meant the object would fly off in the direction the mouse had relative to its previous location. If you just move your direction vector calculation to immediately before your call to ApplyForce(), it should work fine.
Coordinator
Oct 29, 2007 at 12:07 PM
ClearForce() is really only meant to be used internally by the engine.

When you apply forces using ApplyForce, the engine adds it to a total force accumulator. Then, when the physics simulator is updated, it applys the summed forces all at once and then clears the summed forces to get ready for the next update.

So, when you ApplyForce in one update, that force is gone the next.
Oct 30, 2007 at 10:20 PM
Ok, its working now but i have another question. how would one make the arrow "stick" into another Body.
Coordinator
Oct 30, 2007 at 10:50 PM
When the body hits, create a AngleJoint and a RevoluteJoint at the point of contact and between the arrow and the body it hit. This will act like a "fixed" joint.