[Solved] Body not Stopping using these => body.Enabled=false and body.ResetDynamics()

Topics: User Forum
Aug 6, 2012 at 2:30 AM
Edited Aug 6, 2012 at 2:33 AM

Could someone advise me why my physics body is not stopping when I use the following code. I've checked Farseer Body.cs and Body.ResetDynamics() method, it resets LinearVelocity, Force, AngularVelocity and Torque to ZERO, meaning it should stop the physics body to full stop.

Please advise.

this.bullets[index].Body.Enabled = false;
bullets[index].Body.ResetDynamics();

bullets[index].SpeedLinear = Vector2.Zero;    //constant linear speed 
bullets[index].SpeedLinearMax = Vector2.Zero; //Max limit linear speed
bullets[index].SpeedRotation = 0f;            //constant rotation speed
bullets[index].SpeedRotationMax = 0f;         //Max limit rotation speed 
//Update code....
//If SpeedLinear is Set to ZERO, thus impulse should stop impacting the body
this.Body.ApplyLinearImpulse(this.Direction * (SpeedLinear * (float)gameTime.ElapsedGameTime.TotalSeconds));

Coordinator
Aug 7, 2012 at 1:30 AM

Setting the Body.Enabled to false will stop it as it will no longer be included in the simulation update loop.
Make sure that your "index" variable is the correct one - I suspect that you are setting the Enabled property on the wrong body.

Aug 7, 2012 at 5:00 AM

@Genbox - Thank you. I figured out what the issue was. In my game I make my objects wrap the screen. In my wrap screen check, I forgot to use ConvertUnits.ToSim(whatever var)...so my physics objects kept applying impulse.

Once I fixed the Wrap Boundary check, all worked as expected.