How to set up interactive and non-interactive objects in PhysicsJS?

I am trying to set up a swing with userdragable objects. After creating the world in JS physics, mouse interaction is added

world.add( Physics.behavior('interactive', { el: renderer.el }) );

which works great. Subsequently, I want some added objects to be dragged (box objects). But the lever cannot be dragged, but it must interact with the boxes. Therefore, the lever must rotate in accordance with the replaced box. Fulcourm is placed in a non-interactive way, setting its property treatmentto static:

world.add( Physics.body('convex-polygon', {
        name: 'fulcrum',
        x: 250,
        y: 490,
        treatment: 'static',
        restitution: 0.0,
        vertices: [
            {x: 0, y: 0},
            {x: 30, y: -40},
            {x: 60, y: 0},
        ]
    }) );

How can objects interact with each other, but only some of them are userdragable?

The violin is available at: http://jsfiddle.net/YM8K8/

+4
1

... . github. https://github.com/wellcaffeinated/PhysicsJS/issues/101

, , "" .

Physics.behavior('interactive-custom', function( parent ){ ...

:

body = self._world.findOne({ $at: new Physics.vector( pos.x, pos.y ) });

:

body = self._world.findOne({ $at: new Physics.vector( pos.x, pos.y ), $in: self.getTargets() });

, , , , .

:

world.add( 
    Physics.behavior('interactive-custom', { el: renderer.el })
        .applyTo(world.find({ name: 'box' })) 
);

world.find, , "". , .

:

http://jsfiddle.net/wellcaffeinated/YM8K8/1/

+2

Source: https://habr.com/ru/post/1545266/


All Articles