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.
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.
Share asked Apr 7, 2016 at 13:12 MattMatt 511 silver badge4 bronze badges 1- See also MatterJS static angle – ggorlen Commented Jun 22, 2024 at 18:47
2 Answers
Reset to default 6So 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);
Inertia did not work for me.. for now I'm doing this on update.
this.characters[1].setAngle(0)