I am having problems creating p2 physics constraint programatically.
I am using the p2 physics library with PlayCanvas integration.
I am creating a p2RevoluteConstraint programmatically and assigning the 2 entities like so:
var rc = freeBubble.script.create('p2RevoluteConstraint');
rc.entityA = playerBubble;
rc.entityB = freeBubble;
But I get an error on line 1347 of p2-integration.js:
Cannot read property 'off' of null
So I changed the event code to:
if(prev) {
prev.off('p2:newBody');
}
But now the bubbles collide with no errors but the bubble that should be attached just gets pushed away (unaffected by new constraint), which you can see if you play the project, press left click to spawn a bubble, and collide with it using WASD.
I am even logging the 2 entities that collided to console and it states that the entityA and entityB are assigned, but like I said the entities act as if the constraint isn’t even there.
How do I properly create a new constraint in code?
Project overview: https://playcanvas.com/project/722463/overview/bubs