Is it possible to apply physics to sprites but lock their rotations? I’ll be using words inside the sprites and if they rotate it will make harder to read. I want the sprites bouncing around without rotation, keeping the words inside them in the horizontal position.
This is not a default feature of Hype.
This should be a default feature of Hype.
Hey @jonathan – I was playing around with matter.js and this seems like a trivial feature to add.
Apparently, capitalization matters. I tried it and my tomato enemy stopped spinning.
Update - It’s not so trivial. While I was able to stop my tomato from spinning, it started again after I scaled the tomato.
Matter.Body.scale(red, 1, 1);
Even with no actual scaling going on, the tomato started spinning again.
Update #2 - OK, so when the body is scaled, it seems the physics properties are altered somehow.
It says this…
Scales the body, including updating physical properties (mass, area, axes, inertia), from a world-space point (default is body centre).
So, the trick is to just reset the Inertia after scaling the body.
Matter.Body.scale(red, 1, 1); Matter.Body.setInertia(red, 'Infinity');
I realize this adds significant complexity to Annoyed Tomatoes, where the Tomatoes are supposed to bounce and scale – but not rotate. But, the general idea is this… if you add your own code, you might be able to make it work. Also, if Tumult wanted to improve Physics with Hype, adding this setting seems like low-hanging fruit.
Interesting trick; I’ll look into this more as a lock. I could probably also end up fighting the physics system by not setting the rotation of the element and forcing Matter.js to not use the rotated coordinates, but I don’t know what the consequences of that would be.