This project has moved. For the latest updates, please go here.

Interesting problem in Body.ApplyForce()

Topics: Developer Forum
May 11, 2011 at 6:29 AM

I have to bodies: _body and _body2 and tried to apply some force between them.

In the Update procedure, I did the following:
First try:
Vector2 force = _body2.WorldCenter - _body.WorldCenter;
It worked, but I wanted something weaker.
Second try:
Vector2 force = _body2.WorldCenter - _body.WorldCenter;
Now, the game hangs at the point where I apply the force.
If I remove the ApplyForce calls, the game runs, so both Vector2.Normalize() and Body.ApplyForce() work, but not together.
I even tried to manually divide the Vector by its length, but i got the same freezing.

May 11, 2011 at 8:20 AM

Check your values for NaN. I've seen the simulation hang when NaNs are introduced. I've been tempted to commit local changes that Debug.Assert for that problem, just haven't.

Of course, you may be seeing something else, so its just a suggestion. If that's not it I recommend hitting the pause button in visual studio and taking a look at the stack for the thread that is stuck, posting it here if you don't see something to fix.