var Hooked = pc.createScript('hooked');
Hooked.attributes.add("hook", { type: "entity" });
// initialize code called once per entity
Hooked.prototype.initialize = function() {
this.on('attr:hook', function (value, prev) {
this.onHookChange(value, prev);
});
if(this.hook) this.onHookChange(this.hook, null);
};
var center = new Ammo.btVector3( 0, 0, 0 );
Hooked.prototype.onHookChange = function(value, prev) {
if(this.joint) {
console.log("destroy join");
}
if(value) {
console.log("create joint");
this.joint = new Ammo.btPoint2PointConstraint( this.entity.rigidbody.body , this.hook.rigidbody.body, center, center);
console.log("joint:", this.joint);
this.app.systems.rigidbody.dynamicsWorld.addConstraint(this.joint, false);
}
};
// update code called every frame
Hooked.prototype.update = function(dt) {
if (this.joint) {
// render a line between the 2 entities
}
};
Currently this.entity (EntityA) is attracted by this.hook (EntityB) until they collide: how can I add a fixed distance? I tried playing with pivots but couldn’t make it work.
I’ve already read the thread about the robot arm but it seemed very complicated for a simple distance joint.
If I understand correctly, in order to achieve what I want, I will need 3rd body which will have 2 point2pointConstraints : one with the dynamic body and one with the static body.
I have set up 2 entities : “working2d” and “broken2d”.
The only difference is the Ball’s collision sphere radius (Ball1 radius=0.5, Ball2 radius=0.14).