Jump to content

How to remove a constraint in p2


Recommended Posts

of course.. you just should keep track of your constraint..


usually i store the constraint directly on one of the constrained objects..

somesprite.constraint = game.physics.p2.createRevoluteConstraint(somesprite.body, [0,0], someothersprite.body, [0,0], 10000);

then i delete it with:

game.physics.p2.removeConstraint(somesprite.constraint);somesprite.constraint = null;

you could also clear ALL constraints at once:

function clearAllConstraints(){    var allConstraints = game.physics.p2.world.constraints.splice(0,game.physics.p2.world.constraints.length);    if (allConstraints.length > 0){       for (i=0; i<=allConstraints.length; i++){ game.physics.p2.removeConstraint(allConstraints[i]);}   }}

note that i use a workaround to get all constraints because the last time i checked the "getConstraints()" function returned "undefined" (i already reported the bug so it's probably fixed by now)

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...