Closed jimmyyao88 closed 7 years ago
@schteppe
You probably have to set its mass and update the mass properties too. See https://github.com/schteppe/p2.js/wiki#mass-properties
If that doesn't work, you could also create a new body.
@schteppe ,hi Stefan,appreciate ur reply, I edit the example demo:'Canvas: Character demo' in readme,when the Character box jump and touch the platform body,I hope the platform body will drop down beacuse of the gravity,Here is the code:
world.on('beginContact', function (evt){
..code...
for(var i=0;i<platforms.length;i++){
//follow what u said : update the body's mass property
platforms[i].mass = 1;
platforms[i].type = p2.Body.DYNAMIC;
console.log('updated')
}
});
BUT , it seems dosent work, is it means the only way to make the body have influence by World Gravity and drop down is to create a new body?
Did you try running . updateMassProperties() too? As in the wiki?
@schteppe AWESOME! LIFESAVER
Hi Stefan ,Here is a Kinematic body move from left to right , i control another body to jump on that body , weirdly, the kinematic body go to the top .... what i want is the body back to DYNAMIC and down to the ground....
world.on("beginContact",function(evt){
if(evt.bodyA === platformBody && evt.bodyB === boxBody ) {
platformBody.type = p2.Body.DYNAMIC;
};
})