最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Matter.js body without rotation around its center - Stack Overflow

programmeradmin0浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 6

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

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

this.characters[1].setAngle(0)
发布评论

评论列表(0)

  1. 暂无评论