Famo.us add repulsion to particles? -


based on how add walls famo.us physics simulation? there ball bounce off of walls

how go adding repulsion particle never hit walls?

var engine          = require('famous/core/engine'); var surface         = require('famous/core/surface'); var eventhandler    = require('famous/core/eventhandler'); var view            = require('famous/core/view'); var transform       = require('famous/core/transform');  var statemodifier   = require('famous/modifiers/statemodifier');  var physicsengine   = require('famous/physics/physicsengine'); var body            = require('famous/physics/bodies/body'); var circle          = require('famous/physics/bodies/circle'); var wall            = require('famous/physics/constraints/wall');  var repulsion       = require('famous/physics/forces/repulsion');  module.exports = function () {      var context = engine.createcontext();      var contextsize = context.getsize();      var handler = new eventhandler();      var physicsengine = new physicsengine();      var ball = new surface ({       size: [200,200],       properties: {         backgroundcolor: 'red',         borderradius: '100px'       }     })      ball.state = new statemodifier({origin:[0.5,0.5]});      ball.particle = new circle({radius:100});      var replusion = new repulsion();     ball.particle.applyforce(replusion);      physicsengine.addbody(ball.particle);      ball.on("click",function(){       ball.particle.setvelocity([1,1,0]);     });      context.add(ball.state).add(ball)      var leftwall    = new wall({normal : [1,0,0],  distance : contextsize[0]/2.0, restitution : 0.5});     var rightwall   = new wall({normal : [-1,0,0], distance : contextsize[0]/2.0, restitution : 0.5});     var topwall     = new wall({normal : [0,1,0],  distance : contextsize[1]/2.0, restitution : 0.5});     var bottomwall  = new wall({normal : [0,-1,0], distance : contextsize[1]/2.0, restitution : 0.5});      physicsengine.attach( leftwall,  [ball.particle]);     physicsengine.attach( rightwall, [ball.particle]);     physicsengine.attach( topwall,   [ball.particle]);     physicsengine.attach( bottomwall,[ball.particle]);      engine.on('prerender', function(){       ball.state.settransform(ball.particle.gettransform())     }); }; 

my first thought add repulsion ball's particle, doesn't seem working.

has done or there documentation type of behavior?

i've played around , think have better idea now.

this code 2 balls (particles) in same physics engine repel ( 1 chase other around )

var context = engine.createcontext();  var contextsize = context.getsize();  var handler = new eventhandler();  var physicsengine = new physicsengine();  var ball = new surface ({   size: [200,200],   properties: {     backgroundcolor: 'red',     borderradius: '100px'   } })  ball.state = new statemodifier({origin:[0.4,0.3]});  ball.particle = new circle({radius:100});  var ball2 = new surface ({   size: [200,200],   properties: {     backgroundcolor: 'green',     borderradius: '100px'   } })  ball2.state = new statemodifier({origin:[0.3,0.3]});  ball2.particle = new circle({radius:100});  var leftwall    = new wall({normal : [1,0,0],  distance : contextsize[0]/4.0, restitution : 0.3}); var rightwall   = new wall({normal : [-1,0,0], distance : contextsize[0]/4.0, restitution : 0.3}); var topwall     = new wall({normal : [0,1,0],  distance : contextsize[1]/4.0, restitution : 0.3}); var bottomwall  = new wall({normal : [0,-1,0], distance : contextsize[1]/4.0, restitution : 0.3});  physicsengine.attach( leftwall,  [ball.particle, ball2.particle]); physicsengine.attach( rightwall, [ball.particle, ball2.particle]); physicsengine.attach( topwall,   [ball.particle, ball2.particle]); physicsengine.attach( bottomwall,[ball.particle, ball2.particle]);  physicsengine.addbody(ball.particle);   physicsengine.addbody(ball2.particle); 

the repulsion has added pe target , source, both of must exist in engine.

var replusion = new repulsion({strength: 90}); physicsengine.attach(replusion, [ball2.particle], ball.particle);  ball.on("click",function(){   ball.particle.setvelocity([1,0,0]); });   ball2.on("click",function(){   ball2.particle.setvelocity([1,1,0]); });  context.add(ball.state).add(ball) context.add(ball2.state).add(ball2)  engine.on('prerender', function(){   ball.state.settransform(ball.particle.gettransform())   ball2.state.settransform(ball2.particle.gettransform()) }); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -