How to use ApplyForce with box2DWeb -


i have box2dweb sketch working ok unable figure out how use applyforce method body. have attached working codepen. on line 85, have commented out line thought work disappears when include it.

if let me know correct way use it, happy. have rtfm , seen similar posts on stacko still cannot work out.

http://codepen.io/anon/pen/vojbyn?editors=101

thanks lot,

steven

// single dynamic object----------------------   var fixdef2 = new b2fixturedef;   fixdef2.density = 1.0   fixdef2.friction = 0.2;   fixdef2.restitution = 0.5;    var bodydef2 = new b2bodydef;   bodydef2.type = b2body.b2_dynamicbody;    fixdef2.shape = new b2polygonshape;   fixdef2.shape.setasbox((300/scale)/2, (60/scale) / 2);    bodydef2.position.x = canvas.width/4/scale;   bodydef2.position.y = canvas.height/2/scale;   bodydef2.angle = 5;    world.createbody(bodydef2).createfixture(fixdef2);  // apply force object---------------------- /*bodydef2.applyforce(new b2vec2(500,50) , bodydef2.getworldcenter()); */ 

you should call applyforce method of b2body, not of b2bodydef. can b2body object result of world.createbody(bodydef2) method.

i've changed codepen here: http://codepen.io/anon/pen/nqzvqg

your code:

world.createbody(bodydef2).createfixture(fixdef2);  // apply force object---------------------- /*bodydef2.applyforce(new b2vec2(500,50) , bodydef2.getworldcenter()); */ 

my code:

var mybody = world.createbody(bodydef2); var myfixture = mybody.createfixture(fixdef2);  // apply force object mybody.applyforce(new b2vec2(500,50), mybody.getworldcenter()); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -