I didn't either, until today. HA HA!
Over the past few days, I had a bad case of writer's block. But this morning, after seeing your post (and realizing that the game section isn't complete without collision detection) I decided to try once again.
The matter.js documentation and demo covers the basics of "sensors".
- Matter.js Demo · code by @liabru
- matter-js/examples/sensors.js at master · liabru/matter-js · GitHub
...the example targets the bodies directly, but that gets tedious for game development. There's something called "collision filters", but that's more programming. Isn't there something more Hype like?
Since I just wrote the "Game Data" chapter, which covers custom attribute data, I decided to try that. It totally works and works well! Instead of adding every platform in the game as a collision group, I simply gave it a "data-ground" attribute. Then, using three sensors (main, left and right) the game actually jumps like a platformer — including wall jumping.
Matter.Events.on(hypeDocument.getElementProperty(hypeDocument.getElementById("sensor"), "physics-engine"), "collisionStart", function (event) {
var pairs = event.pairs;
for (var i = 0, pl = pairs.length; i < pl; ++i) {
var pair = pairs[i];
if (pair.bodyA.elementId === "sensor") {
var bonk = hypeDocument.getElementById(pair.bodyB.elementId);
if (bonk.hasAttribute("data-ground")) {
window.ground = true;
}
}
}
});
The trick is the "hasAttribute" method. Also, what was tripping me up, is that the matter.js example does the "collisionStart", "collisionEnd", "collisionActive" as its own function. I was running it with every keypress and flooding the console.log. I was like... what's with this API?! HA HA. So now, I just set the collision detection at the start.
Anyway, I'm planning to cover this in the Hype book, but the template is online.
Template Post — Physics Mini Templates for Tumult Hype 4 - #23 by Photics
Animated GIF of wall jumping — Physics Mini Templates for Tumult Hype 4 - #27 by Photics