impulse.js 613 B

1234567891011121314151617181920212223242526
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. impulse: cc.v2(0, 1000)
  5. },
  6. onBeginContact: function (contact, selfCollider, otherCollider) {
  7. var manifold = contact.getWorldManifold();
  8. if (manifold.normal.y < 1) return;
  9. let body = otherCollider.body;
  10. body.linearVelocity = cc.v2();
  11. body.applyLinearImpulse(this.impulse, body.getWorldCenter());
  12. },
  13. // use this for initialization
  14. onLoad: function () {
  15. },
  16. // called every frame, uncomment this function to activate update callback
  17. // update: function (dt) {
  18. // },
  19. });