Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matter.js body without rotation around its center

I am working with Matter.js and I am struggling with many aspects because it's very hard to find anything in the documentation.

The most important thing I would like to know is how to make this body:

Game.characters[1] = Game.Bodies.rectangle(x, y, c_width, c_height, {
    id: "character1",
    isStatic: false,
    friction: 0.002
});

not rotate around its center. I want this body to be character sprite with frame animations and I just want it to be able to jump and move left or right, but not tilt if it hits an edge or if it does anything that would make it tilt.

like image 228
Matt Avatar asked Oct 28 '25 06:10

Matt


1 Answers

So I had the same question but just found the answer.

According to the developer of Matter.js setting inertia of a body to Infinite prevents the body from rotation on collision.

When creating a Matter.Body, set the inertia property of the body to Infinity:

const options = {
    inertia: Infinity,
}
let body = Matter.Bodies.rectangle(x, y, width, height, options);
like image 88
Oli414 Avatar answered Oct 29 '25 20:10

Oli414



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!