2008-07-21
Use Modulo for Box2D Rotation
Not sure if this is really a bug but while playing with Box2D, which btw is really amazing, I stumbled upon a nasty behaviour that stopped my sprites from working like expected. Just wait few (10+) seconds to see what I am talking about.

Someone also posted more details about it. The solution is simple: Use modulo within the enterFrameHandler to assign proper values to the rotation property.The movie is using a b2Body + attached Sprite and a b2RevoluteJoint motor responsible for the rotation + DebugDraw enabled. Suddenly after about 10 seconds the attached sprite stops rotating. Thanks to great support of the Box2D community I finaly realised what was actually going on. Apparently when the Movieclip rotation values pass 32767 (which is about 91 rotations) it either stops rotating or behaves unexpected. Although this is not a Box2D specific issue I believe that the AS3 port of Box2D will offer real world scenarios for this bug.
-
public function enterFrameHandler(e:Event):void
-
{
-
b2world.Step(2/15, 10);
-
for (var bb:b2Body = b2world.m_bodyList; bb; bb = bb.m_next){
-
if (bb.m_userData is Sprite){
-
bb.m_userData.x = bb.GetPosition().x * 30;
-
bb.m_userData.y = bb.GetPosition().y * 30;
-
bb.m_userData.rotation = (bb.GetAngle() *(180/Math.PI))%360 ;
-
}
-
}
-
}
To fix this simply use Modulo within the enterFrameHandler!
3 Comments
-
[...] - bookmarked by 5 members originally found by valenessa on 2008-08-06 Use Modulo for Box2D Rotation http://manfred.dschini.org/2008/07/21/use-modulo-for-box2d-rotation/ - bookmarked by 1 members [...]
-
Hey - I was having the same problem, which I assumed was a Box2D bug, but this solved it for me … thanks for posting!
-
[...] public links >> box2d Use Modulo for Box2D Rotation First saved by SiloinSiproche | 2 days ago Box2D Hourglass First saved by lovlygrl101 | 2 days [...]

