Hi Senior, I want to ask about body in XR, I use Cannon for body engine and use ecys as storage. I want when the object is draggable, the body will follow the object’s position. but in my case, when the object is draggable, the body does not follow the object and it doesn’t make sense.
its my code :
export class DraggablePhysiqueSystem extends System {
execute() {
this.queries.draggable.results.forEach(entity => {
const draggable = entity.getMutableComponent(DraggablePhysique);
const object = entity.getComponent(Object3D).object;
const body = entity.getComponent(Object3D).body;
if (draggable.originalParent == null) {
draggable.originalParent = object.parent;
}
switch (draggable.state) {
case 'to-be-attached':
draggable.attachedPointer.children[0].attach(object);
draggable.state = 'attached';
break;
case 'attached':
body.position.copy(draggable.attachedPointer.position);
body.quaternion.copy(draggable.attachedPointer.quaternion);
body.velocity.set(0, 0, 0);
// body.position.copy(object.position);
// body.quaternion.copy(object.quaternion);
// body.velocity.set(0, 0, 0);
break;
case 'to-be-detached':
draggable.originalParent.attach(object);
draggable.state = 'detached';
break;
case 'detached':
if (body.position !== object.position) {
object.position.copy(body.position);
object.quaternion.copy(body.quaternion);
}
break;
default:
object.scale.set(1, 1, 1);
}
});
}
}
DraggablePhysiqueSystem.queries = {
draggable: { components: [DraggablePhysique] }
};
thank you