javascript - How to setup interactive and non-interactive objects in PhysicsJS? -



javascript - How to setup interactive and non-interactive objects in PhysicsJS? -

i trying setup seesaw userdragable objects. after world creation in physicsjs, mouse drag interaction added by

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

which works fine. subsequently, want added objects draggable (the box objects). lever should not draggable, should interact boxes. lever should rotate according replaced box. fulcurm placed in noninteractive way setting treatment property 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 interacting each other, userdragable?

a fiddle available at: http://jsfiddle.net/ym8k8/

at moment not supported... should be. i've added bug on github. https://github.com/wellcaffeinated/physicsjs/issues/101

in meantime, if want, can create new "interactive" behavior copying , pasting , alter name.

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

then in grab function create little addition:

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

change to:

body = self._world.findone({ $at: new physics.vector( pos.x, pos.y ), $in: self.gettargets() });

what when it's searching body @ mouse coordinates, check see if body in set you've applied behavior to.

then instead of adding behavior before bodies in fiddle, add together @ end, , this:

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

this utilize world.find find bodies in world have "box" name. sends array of bodies behavior , tells behavior apply bodies.

here's modified fiddle:

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

javascript physicsjs

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -