Matter.js Setting Collision Rules

Source: Internet
Author: User

Matter is a good set of JS physics engine, Layaair built-in, become more useful

matter provides a collisionfilter attribute for each collision, and supports three properties, namely

Group
Category
Mask

With three attributes, you can design a complex collision relationship.

The rules are as follows:
First case

On the premise that two group is equal
If any group is greater than 0, then the two always collide, for example, everyone is 1, and this is a direct collision between us.
If any group is less than 0, for example everyone is-1, then everyone will never collide
In addition to the above two cases, according to category and mask to determine

Second case

Under the premise that the two group is not equal
Judging by category and mask

Judging by category and mask

Category,mask decision Rules
Category represents a collision classification whose value can be 1,2,4,8 ... until 2^31, each rigid body sets a value
Mask is a collision set (category collection), which is the result value of category phase, such as accepting the 2,4 type, with a value of 6
A and B collision situations are
The mask of a must contain the category of B, and the Mask of B must also contain category A, i.e.
(A.category & B.mask)!== 0 && (b.category & A.mask)!== 0

Summarized as follows:
Simple collision relationship, directly set group can
Complex collision relationships that can be matched by setting category and mask values to make a very high-level collision relationship

With my little physics game.

Matter.js Setting Collision Rules

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.