javascriptmatter.jsphaserjs

No friction on tweened sprite


I have a moving platform and box on top of it. No matter how fast the platform is moving, the box doesnt move sideways along with the platform and eventually falls down if the platform slipped away.

I tried different combinations of friction and frictionStatic.

   const box = this.matter.add.rectangle(700, ScreenHelper.sceneWrapperSize.height - 110, 20, 20, {
      collisionFilter: {
        category: CAT_BLOCK_A,
        mask: CAT_FLOOR,
        group: 0
      },
      friction: 1,
    })

    const platform = this.matter.add.sprite(664, ScreenHelper.sceneWrapperSize.height - 100, "brick", undefined, {
      isStatic: true,
      collisionFilter: {
        category: CAT_FLOOR,
        mask: CAT_PLAYER | CAT_PLAYER_BOTTOM_SENSOR | CAT_BLOCK_A,
        group: 0
      },
      friction: 1,
      frictionStatic: 1,
    });
    platform.setDisplaySize(200, 20)

    this.tweens.add({
      targets: platform,
      x: 300,
      ease: Phaser.Math.Easing.Quintic.InOut,
      duration: 3000,
      yoyo: true,
      repeat: -1
    });

Solution

  • Well the short answer, it is not possible with tweens, as far as I know (without some weird, hack/workaround), because Tweens set the x position, and this bypasses the physics calculations! (btw.: static matter Object can't be really "moved")

    Warning: Overriding the body.position might kinda work, but because it is a static body, it won't work as one might hope (since this also overrides some of the physics calculations). If you make the platform a dynamic body, collisions with the player, would also stop/alter the movement of the platform, and ... many other issues

    Maybe using Contraints might work (link to documentation), but this would be more a pendulum, than a moving platform.