Matt
Matt

Reputation: 51

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.

Upvotes: 4

Views: 3691

Answers (2)

Merlin
Merlin

Reputation: 1

Inertia did not work for me.. for now I'm doing this on update.

this.characters[1].setAngle(0)

Upvotes: 0

Oli414
Oli414

Reputation: 346

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);

Upvotes: 6

Related Questions