My behaviors on initialization are added as follows:
world.add([
Physics.behavior('interactive', { el: renderer.el }),
Physics.behavior('constant-acceleration'),
Physics.behavior('body-impulse-response'),
Physics.behavior('sweep-prune'),
edgeBounce
]);
I'd like to, at a later time, remove the "constant-acceleration" behavior. I read a couple of posts that said to use the remove() method but I'm not getting anything to happen using it like follows:
world.remove( Physics.behavior('constant-acceleration') );
Can anyone advise how I could achieve removing a specific behavior from the world after it has been added?
The
Physics.behaviordocs indicate that aBehaviorobject is returned when you callPhysics.behavior(because it constructs a new one). So you need to keep a reference to theBehaviorobject you'd get back from the call you've put into yourworld.addarray, then pass that reference toworld.removelater. As it is now, you're making a newBehavior(separate from the one you made first) and immediately passing that brand new object toworld.remove, which will basically do nothing.