Chipmunk applyForce error with offset param (web/android)

Chipmunk applyForce error with offset param (web/android)
0

#1

Hi, I’m having a strange problems with
[ Cocos2dx v3.1,Using JS language and building in Android and Web ]
doing the code below:

const SandboxScene3 = cc.Scene.extend({
  listener: null,
  space: null,
  layer: null,
  phDebugNode: null,
  onEnter: function() {
    this._super();

    this.listener = cc.EventListener.create({
      event: cc.EventListener.TOUCH_ONE_BY_ONE,
      swallowTouches: true,
      onTouchBegan: () => true,
      onTouchMoved: () => true,
      onTouchEnded: (touch, evt) => this._touch(touch)
    });
    cc.eventManager.addListener(this.listener, 1);

    this.space = new cp.Space();
    this.space.gravity = cp.v(0, 0);

    this.layer = new cc.Layer();
    this.addChild(this.layer);

    this.phDebugNode = cc.PhysicsDebugNode.create(this.space);
    this.phDebugNode.setName('PhysicsDebugNode');
    this.layer.addChild(this.phDebugNode, 10);

    this.scheduleUpdate();
  },
  _touch: function(touch) {
    const body = new cp.Body(1, cp.momentForCircle(1, 0, 8, cp.vzero));
    this.space.addBody(body);

    const shape = new cp.CircleShape(body, 16, cp.vzero);
    shape.setElasticity(1);
    shape.setFriction(0);

    this.space.addShape(shape);

    body.setPos(cp.v(touch.getLocation().x, touch.getLocation().y));
    // PROBLEM
    body.applyForce(cp.v(0, 50), cp.vzero);
  },
  update: function(dt) {
    this.space.step(dt);
  }
});

Im trying to create a body in a zero gravity space, and when force is applied to the body it has an strange behavior.

Scenario: Running in chrome and using .applyForce(cp.v(0, 50), cp.vzero);

  • Works seems to work well
  • Not rotates cause force seems to be applied to center of the body

Scenario: Running in android and using .applyForce(cp.v(0, 50), cp.vzero);

  • It does not move just rotates in the same position
  • It is like of point where force it is applied it is not the center

Scenario: Running in chrome and using .applyForce(cp.v(0, 50), body.local2World(cp.vzero));

  • It rotates fast
  • Moves slow in the direction of the force

Scenario: Running in android and using .applyForce(cp.v(0, 50), body.local2World(cp.vzero));

  • Not rotates
  • Move but very slow in the direction of the force

I would like to know if I’m doing something wrong or it is a bug in Cocos2dx

I’d appreciate any help on this
Thanks in advance