Question

my jsfiddle : http://jsfiddle.net/H8e9m/11/

as you can see when the ball reach the pendulum end and collide with it by a revolute joint, the problem occurred when trying to make the ball release the pendulum by pressing the space button.

      if (keydown.space) {
        var list = physics.world.GetJointList();
         if (list.GetBodyB().m_userData.details.name=="End")
              physics.world.DestroyJoint(list);
            }

can anyone tell me how can i fix this problem please

Was it helpful?

Solution

You can keep a reference to the joint when you create it like this:

var myJointDef = new b2RevoluteJointDef();
revoluteBall_jointDef.bodyA = ...
... etc
myJoint = world.CreateJoint(jointDef);

The 'myJoint' variable should be global, eg. you could declare it here:

var myJoint = null;

$(document).ready(function () {
    var b2Vec2 = Box2D.Common.Math.b2Vec2
       ,b2AABB = Box2D.Collision.b2AABB
       ... etc

Then you should be able to destroy the joint from any point in your code later.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top