Lock Sprite Rotation When Using Physics


(MMuser) #1

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.


(π•„π•šπ•”π•™π•’π•–π• 𝔾𝕒𝕣𝕠𝕗𝕒𝕝𝕠) #2

This is not a default feature of Hype.
This should be a default feature of Hype.

Using the JavaScript API, you could try setting the rotateZ value to zero with every frame update… requestAnimationFrame…


Is there a Physics API? πŸ€”
(π•„π•šπ•”π•™π•’π•–π• 𝔾𝕒𝕣𝕠𝕗𝕒𝕝𝕠) #3

Hey @jonathan – I was playing around with matter.js and this seems like a trivial feature to add.

inertia: 'Infinity'

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.


(Jonathan Deutsch) #4

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.