bossikkk Posted July 10, 2018 Share Posted July 10, 2018 I use matter physics. As a basis, I took this example: link Removed wall jump and add up sensor. And in these fragments of the code I tried to implement the: function create(){ this.matter.world.on('collisionstart', function (event) { var left = playerController.sensors.left; var right = playerController.sensors.right; var up = playerController.sensors.up; for (var i = 0; i < event.pairs.length; i++) { var bodyA = event.pairs[i].bodyA; var bodyB = event.pairs[i].bodyB; if (bodyA === up || bodyA === right || bodyA === left) { console.log('wtf'); } if (bodyB === up || bodyB === right || bodyB === left) { if (bodyA.gameObject) { if (bodyA.gameObject.tile.layer.name === "behindGround2") { bodyA.collisionFilter.category = 0; touchedTiles.push(bodyA); setTimeout(() => { restoreCollision = true; }, 400); } } else { if (bodyA.parent.gameObject.tile.layer.name === "behindGround2") { bodyA.parent.collisionFilter.category = 0; touchedTiles.push(bodyA.parent); setTimeout(() => { restoreCollision = true; }, 400); } } } } }) } function update(){ if (!playerController.blocked.bottom && matterSprite.anims.currentAnim.key === 'jump') { if (touchedTiles.length > 0 && restoreCollision) { restoreCollision = false; touchedTiles.forEach((el, index, arr) => { el.collisionFilter.category = 1; if (index === arr.length - 1) { touchedTiles = []; console.log('Array is cleared'); } }); } } } Game screen: Is there a working way to do this? My code works through time to time. Very often the player simply stops flying through the object. Link to comment Share on other sites More sharing options...
Recommended Posts